Friday, June 28, 2019

Client Script > Retrieve Values from URL

This script sample shows how to retrieve a parameter values from URL (?param1=value1&m2=value2&m3=value3) . It can be used for example for setting a different pop-up forms for new Contact if it is created from Customer record or Vendor record subtab.


// This function search for all parameters and returns value for set parameterfunction GetUrlValue(VarSearch){    var SearchString = window.location.search.substring(1);    var VariableArray = SearchString.split('&');    for(var i = 0; i < VariableArray.length; i++){        var KeyValuePair = VariableArray[i].split('=');        if(KeyValuePair[0] == VarSearch){            return KeyValuePair[1];                    }    }}function clientPageInit(type){  if (type = "create") {      var form = nlapiGetFieldValue('customform');    var recType=GetUrlValue('parentType');  		    // As the page is always loaded again when form is set and also Page Init Function is triggered again we have to stop this infinite loop.       if ((form == 17)&&(recType == "vendor")){return;}    if ((form == 18)&&(recType == "custjob")){return;}      // If Contact is created from Vendor we want to set Custom Form ID 17    if (recType == "vendor"){  	nlapiSetFieldValue('customform',17);  		    } 	    // If Contact is created from Customer we want to set Custom Form ID 18    if (recType == "custjob"){  	nlapiSetFieldValue('customform',18);  			    }   }	}	
DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Netsuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.

Netsuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Netsuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.

Netsuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.

No comments:

Post a Comment