List Collector to Populate Affected CI's Related List
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2013 08:34 AM
Hi Everyone!
I have a requirement to add in a glide list field on the change form (the list collector with a lock in it) to populate the affected CIs related list.
I copied modified two business rules that is populating the related list, but it is adding the first choice over and over again and not adding the other CIs. I'm thinking I'd have to copy and modify the script include "ChangeCollisionHelper". Any ideas?
Sync CI in affected Cis List Picker
if (!previous.u_additional_affected_cis.nil())
removePreviousCI();
if (!current.u_additional_affected_cis.nil())
addCurrentCI();
function removePreviousCI() {
// Delete Affected CI records for this task and previous CI
var rec = new GlideRecord('task_ci');
rec.addQuery('task', current.sys_id);
rec.addQuery('ci_item', previous.u_additional_affected_cis);
rec.query();
while (rec.next())
rec.deleteRecord();
}
function addCurrentCI() {
//Create Affected CI record for this task and current CI
var rec = new GlideRecord('task_ci');
rec.addQuery('task', current.sys_id);
rec.addQuery('ci_item', current.u_additional_affected_cis);
rec.query();
if (rec.next())
return;
rec.initialize();
rec.task = current.sys_id;
rec.ci_item = current.u_additional_affected_cis;
rec.insert();
}
Add CI in affected Cis List Picker
perform();
function perform(){
if(!ChangeCollisionHelper.isCiInAffectedCis(current.u_additional_affected_cis,current.sys_id)){
ChangeCollisionHelper.addCiToChangeAffectedCis(current.u_additional_affected_cis,current.sys_id);
}
}
Thanks in advance for any help you can provide.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2014 03:13 AM
Hi,
Did you ever find a solution to this as I have a similar requirement?
Thanks
Dan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2014 05:30 AM
Anywhere you see something like:
current.sys_id
Change it to
current.getValue('sys_id')
Think of current as a pointer. When you assign it to another variable, you're copying the reference, not the value. It took me to 4th year college for someone to explain it in detail to me so I won't dive in here. Suffice it to say, using getValue() can get you out of a lot of weird spots - copying sys_ids inside a loop is the most common.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2014 05:33 AM
Thank you,
I will give it a go.
Cheers,
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 12:20 PM
did you get a solution for this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2023 11:04 PM
I have also similar requirement to add in a glide_list field value on the change form to populate the affected CIs related list.
so i have created a before (insert-Update) BR with condition Field name Changes
(function executeRule(current, previous /*null when async*/ ) {
if (!previous.field_name.nil() || !previous.field_name.changes())
removePreviousCI();
if (!current.field_name.nil())
addCurrentCI();
function removePreviousCI() {
var arr = [];
var str = previous.field_name.toString().split(',');
arr.push(str);
var tam = arr.length;
for (var i = 0; i < tam; i++) {
var receda = new GlideRecord('cmdb_ci');
receda.addQuery("sys_id", arr[i]);
receda.query();
while (receda.next()) {
var service = receda.getUniqueValue();
// Delete Affected CI records for this task and previous CI
var rec = new GlideRecord('task_ci');
rec.addQuery('task', current.sys_id);
rec.addQuery('ci_item', service);
rec.query();
while (rec.next())
rec.deleteRecord();
}
}
}
function addCurrentCI() {
//Create Affected CI record for this task and current CI
var arr = [];
var str = current.field_name.toString().split(',');
arr.push(str);
var tam = arr.length;
for (var i = 0; i < tam; i++) {
var reced = new GlideRecord('cmdb_ci');
reced.addQuery("sys_id", arr[i]);
reced.query();
while (reced.next()) {
var service = reced.getUniqueValue();
var rec = new GlideRecord('task_ci');
rec.initialize();
rec.task = current.sys_id;
rec.ci_item = service;
rec.insert();
}
}
}
})(current, previous);
Thank you!