How to set task short description based on list collector values

Sue143
Tera Expert
Hi guys!
 
I need to retrieve the information stored in the column "comments" from the table my list collector is pointing to into the task description, so far I have achieved to get only the "comments" from the first value selected in the list collector, but I need all the "comments" from the values selected on the list collector.
Can somebody point what is missing in my code, please? 
 
var collector = current.variables.role.toString().split(',');
var collectorLength = collector.length;
for (var i = 0; i < collectorLength; i++) {
    var gr = new GlideRecordUtil().getGR('u_cmdb_ci_role', collector[i]);
    gr.get(collector[i]);
    task.description = gr.comments + ", ";
}
 
Any help will be appreciated.
 
Thank you!
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

If your loop is working, you are overwriting/resetting the task description each time through, so try instead

 

 

    task.description += gr.comments + ", ";

 

A more efficient way to accomplish the same is by only executing the GlideRecord once:

 

var collector = current.variables.role.toString().split(',');
var gr = new GlideRecord('u_cmdb_ci_role');
gr.addQuery('sys_id', 'IN', current.variables.role);
gr.query();
while (gr.next()) {
    task.description += gr.comments + ", ";
}

 

 

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

If your loop is working, you are overwriting/resetting the task description each time through, so try instead

 

 

    task.description += gr.comments + ", ";

 

A more efficient way to accomplish the same is by only executing the GlideRecord once:

 

var collector = current.variables.role.toString().split(',');
var gr = new GlideRecord('u_cmdb_ci_role');
gr.addQuery('sys_id', 'IN', current.variables.role);
gr.query();
while (gr.next()) {
    task.description += gr.comments + ", ";
}

 

 

@Brad Bowman  That is exactly what was happening! 😄 thanks