How to pass value from one variable to another using JavaScript in CA Workload Automation DE

Document ID : KB000098250
Last Modified Date : 28/05/2018
Show Technical Document Details
Introduction:
Using JavaScript you can convert variables, including builtin and pass the value to another variable.  This may be helpful in setting variable for Alerts and builtin commands.
Question:
How to pass value from one variable to another using JavaScript in CA Workload Automation DE?
Environment:
CA Workload Automation DE 11.3.x, R12.x
Answer:
Here is an example of a variable trying to pass a value of another variable. 
//eventname = 'NITIN'
//Split on I and take second value, 1.  First split place will be 0.
var myvar = APPL._eventprefix.split('I')[1]; 
//toString method
APPL.VAR2 = myvar.toString();

The result can used be in builtin DE command(s) like this:
if (APPL.VAR2 == 'T') 
{resetResourceProperty('SOMERESOURCE1','Availability','1');  } 
else if 
(APPL.VAR2 == 'SOMETHINGELSE') 
{resetResourceProperty('SOMERESOURCE2','Availability','0'); }


 
Additional Information:
Note: Make sure the initial variable has a value or resolves to some value.  If it results in a blank, then you will see the following error:
Error executing application-level runtime JavaScript script to_string for application MY_APPLICATION. 
The error is: org.mozilla.javascript.EcmaError: TypeError: Cannot call method "toString" of undefined (<wascope>#3)