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

Hi Abhijit , undefined was removed but the other variable values which are not visible on RITM also populating the values in ad group.

see below attached rounded values and also not showing values in a line .

find_real_file.png 

Which fields to show or which fields to hide, what parameters decides that? you will have to use that logic in script.
By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hi Abhijit, 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.

There is no way to validate that in BR as far as I am aware of. However, we have it in client script as below.

g_form.isVisible

I suggest you to understand how your logic is implemented to show/hide fields, there must be something which is getting checked to show/hide fields. if so then you can use same parameters here while concatenating values.

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

Anusha25
Tera Contributor

Hi all, Due to default values in backend unable to achieve so  cleared all values before submit and implemented the below script in workflow . It worked.

var a, b, c, d, e, f, g;
a = current.variables.active_directory_groups.getDisplayValue().toString().split("\n");
b = current.variables.active_directory_groups_sit_env.getDisplayValue().toString().split("\n");
c = current.variables.active_directory_groups_dev_env.getDisplayValue().toString().split("\n");
d = current.variables.modify_active_directory_groups.getDisplayValue().toString().split("\n");
e = current.variables.active_directory_groups_UAT.getDisplayValue().toString().split("\n");
f = current.variables.active_directory_groups_newordelete.getDisplayValue().toString().split("\n");
var str = '';
if(a!='')
str+= a+'; ';
if(b!='')
str += b+'; ';
if(c!='')
str += c+'; ';
if(d!='')
str += d+'; ';

if(e!='')
str += e+'; ';

if(f!='')
str += f+'; ';

current.variables.ad_groups=str;

 

Thank you all for support.