How to set multiple variable values in a single variable using Run Script(workflow)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2022 02:52 AM
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.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2022 07:36 PM
Hi Anusha,
Just tried in my PDI as you expected.
Logic:
var c, d;
c = current.variables.details1.toString().split("\n"); //map your variable names
d = current.variables.details2.toString().split("\n");
for (var i = 0; i < c.length; i++) {
current.variables.details3 = current.variables.details3 + c[i] + ";";
}
for (var j = 0; j < d.length; j++) {
if (d.length == j + 1) {
current.variables.details3 = current.variables.details3 + d[j] ;// to ignore semicolon for the last word
} else {
current.variables.details3 = current.variables.details3 + d[j]+ ";";
}
}
Hope it helps
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2022 03:26 AM
Hi Murthy, It was worked for 2 variables , but in my scenario there are 7 variables
but those variables based on condition will populate ,how can i set those variable values in one variable.
below is the attachment that may use
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");
g = current.variables.modify_active_directory_groups_dailydropdown.getDisplayValue().toString().split("\n");
for (var i = 0; i < a.length; i++) {
current.variables.ad_groups = current.variables.ad_groups + a[i] + ";" + " ";
}
for (var j = 0; j < c.length; j++) {
if (c.length == j + 1) {
current.variables.ad_groups = current.variables.ad_groups + c[j];
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2022 03:39 AM
Hi,
Instead of splitting it, you can just try to replace '\n' with other character( semicolumn in your case) , it will make easy for you.
Please find updated code below, if you want you can semicolumn while concatenating a,b,c variables at the end.
var a, b, c, d, e, f, g;
a = current.variables.active_directory_groups.getDisplayValue().toString().replace("\n",";");
b = current.variables.active_directory_groups_sit_env.getDisplayValue().toString().replace("\n",";");
c = current.variables.active_directory_groups_dev_env.getDisplayValue().toString().replace("\n",";");
d = current.variables.modify_active_directory_groups.getDisplayValue().toString().replace("\n",";");
e = current.variables.active_directory_groups_UAT.getDisplayValue().toString().replace("\n",";");
f = current.variables.active_directory_groups_newordelete.getDisplayValue().toString().replace("\n",";");
g = current.variables.modify_active_directory_groups_dailydropdown.getDisplayValue().toString().replace("\n",";");
current.variables.ad_groups=a+b+c+d+e+f+g;
}
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2022 04:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2022 05:08 AM
Hi Anusha,
Can you confirm all the 7 variables are multi line text type?
And I hope you are setting all values in AD groups variable(so you are not taking the values from that variable?)
e = current.variables.active_directory_groups_UAT
and the above code is for which variable?
Murthy