Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 03:11 AM
I am trying to populate multiple values in string field, I am getting only one value which is last selected one
Please find below script.
(function executeRule(current, previous /*null when async*/ ) {
var plan = current.getValue('plan_s').split(',');
for (var i = 0; i < plan.length; i++) {
gs.info(plan[i] + 'Result');
var client = new GlideRecord("u_table");
client.addQuery('sys_id', plan[i]);
client.query();
while (client.next()) {
current.client_name = client.u_client_name.u_name;
gs.info(client.u_client_name.u_name + 'clientname');
current.client_number = client.u_client_name.u_client_number;
gs.info(client.u_client_name.u_client_number + 'cliennumber');
}
}
})(current, previous);
Regards,
APV Babu
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 03:46 AM
Hello @APV Babu ,
Please give a try to the code below and let me know how it works for you.
(function executeRule(current, previous /*null when async*/ ) {
var plan = current.getValue('plan_s').split(',');
var clientNames = [];
var clientNumbers = [];
for (var i = 0; i < plan.length; i++) {
gs.info(plan[i] + ' Result');
var client = new GlideRecord("u_table");
client.addQuery('sys_id', plan[i]);
client.query();
while (client.next()) {
clientNames.push(client.u_client_name.u_name);
gs.info(client.u_client_name.u_name + ' clientname');
clientNumbers.push(client.u_client_name.u_client_number);
gs.info(client.u_client_name.u_client_number + ' cliennumber');
}
}
current.client_name = clientNames.join(', ');
current.client_number = clientNumbers.join(', ');
})(current, previous);
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
11 REPLIES 11
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 04:18 AM
Thanks for the Response I am not getting any values
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 07:11 AM
I have changed little thing it's working
var clientNames = [];
var clientNumbers = [];
var plan = current.getValue('plan_s').split(',');
gs.info(plan + 'getplan values');
for (var i = 0; i < plan.length; i++) {
gs.info(plan[i] + 'Result');
var client = new GlideRecord("u_table");
client.addQuery('sys_id', plan[i]);
client.query();
while (client.next()) {
var name = client.u_client_name.u_name.toString();
var number = client.u_client_name.u_client_number.toString();
gs.info(client.u_client_name.u_name + 'clientname');
gs.info(client.u_client_name.u_client_number + 'cliennumber');
clientNames.push(name);
clientNumbers.push(number);
}
}
current.client_name = clientNames.join(', ');
gs.info(current.client_name + 'apvb1');
current.client_number = clientNumbers.join(', ');
gs.info(current.client_number + 'apvb2');