How to set multiple variable values in a single variable using Run Script(workflow)

Anusha25
Tera Contributor

After creating Request, few variables like,

variable 1 : A 
                  B
                  C
                  D

variable 2: A1
                  B1
                  C1

variable 3:A2
                 B2
                 C2 etc

In Variable 4(multiple line text)the above 3 variable values should populate  with semicolon and space for each value.

29 REPLIES 29

yes Murthy , all variables are multi line text.

and all variables values are not setting at a time , based on environment variable (type of environment variable was list collector)

when we select environment choice either it should be uat or dev or prod or sit etc or i can select all choices at a time

and other 3 variables are populate based on role (type of role was reference) 

when those multi line variables visible those values should populate in ad_group in a singe line with semicolon separated and space.

 

Hi Murthy, In my scenario ,variable1+variable2+variable3+variable4+variable5 is my expectation ,in some cases variable2 and varaible4 may not be visible to user on request form so here the script is fetching the default value of variable2 and 3 which is wrong. 

 how to identify the hidden variables from the script .

Please  suggest.

Hi Anusha,

I can see only two variables data in your screenshot, could you please show all variable data and paste your updated script as well so that we could help you further.

Thanks and Regard,

Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

yes Abhijit, based on condition those variable will populate , which variable can see on the RITM  that values should populate in ad_group  variable.

ok so other variables which are not visible on the form might not have any values that is the reason it is adding undefined.

so while concatenating, you will have to add one more condition as below to validate if that values is not undefined

if(JSUtil.notNil(a)){

current.variables.ad_groups=current.variables.ad_groups+a;

}

if(JSUtil.notNil(b)){

current.variables.ad_groups=current.variables.ad_groups+b;

}

.

.

.

..

if(JSUtil.notNil(g)){

current.variables.ad_groups=current.variables.ad_groups+g;

}

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP