Using objGlobal to pass optional parameters

RAMP-TS

Using objGlobal to pass optional parameters

Extending the idea in the previous section slightly, you can introduce the concept of optional parameters being passed into scripts. In a script that needs to pass some optional parameters into another script you might find code like this:

objGlobal.OptParms = new Object(); 
objGlobal.OptParms.CustNumber = "12345";
objGlobal.OptParms.CustName   = "ACME ENGINEERING";     
NAVIGATE_TO_SCREEN("uShowCustomer");

and the script that receives the optional parameters you would find code possibly structured something like this:

var CustNumber = "some default value";
var CustName   = "some default value";

if (objGlobal.OptParms != null)
{
   CustNumber         = objGlobal.OptParms.CustNumber;
CustName           = objGlobal.OptParms.CustName;  
objGlobal.OptParms = null;
}

/* Now we proceed to use the values in CustNumber and CustName */

The line objGlobal.OptParms = null; line is very important to this style of processing because it destroys the temporary OptParms object.