- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 03:11 AM
Solved! Go to Solution.
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 04:32 AM
oh there is the issue then.
Could u try something like below. Also plz tell me "plan_s" is of what type (reference/List Collector).
var plan = current.plan_s.split(',');
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 04:33 AM
Its List Collector
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 05:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 03:39 AM - edited 12-26-2023 03:40 AM
If you would like to append values to an existing value you should use :
variabel += valuetoadd ( current.client_name += client.u_client_name.u_name; )
You are currently doing:
variable = valuetoadd ( current.client_name = client.u_client_name.u_name; )
This will overwrite the current value, making it only hold the last one (since that is the last one that has overwritten the value).
Extra info:
using += is actually the same as writing:
variable = variable + valuetoadd
Only its considered a bit more cleaner way of doing so.
String example:
var allwords = "";
var word1 = "Hello "
var word2 = "World!"
allwords += word1
allwords += word2; // allwords is now "Hello World!"
This method also works for numbers/integers to aggregate a total. For example:
var total = 0;
var value1 = 10
var value2 = 5
total += value1 // total = 10
total += value2 // total = 15
- 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