- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2018 08:51 AM
HI All,
I have been looking around the documentation and the forums but cant seem to find an answer to this question. I have a list of CI sysids and i need to populate the Affected CIs section of the incident with the related CIs. Trying to do this in the Business rules as an Incident is created.
any help or direction would be much appreciated.
thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2018 04:43 AM
Perfect. You'll want to do this in a business rule on the incident table with the following settings. I'm guessing on the field name 'u_sysids'. Just make sure that's correct!
Name: Add Affected CIs
When: After
Insert: True
Advanced: True
Condition: current.u_sysids.changes() && !current.u_sysids.nil();
Script:
(function executeRule(current, previous /*null when async*/) {
// Create 'Affected CIs from 'SysIDs' field
var cis = current.u_sysids.split(','); // Split the IDs into an array
// Iterate through the array
for (i=0; i<cis.length; i++) {
// Create a new 'Affected CI' record for each
var aci = new GlideRecord('task_ci');
aci.initialize();
aci.task = current.sys_id; // Associate to this record
aci.ci_item = cis[i];
aci.insert();
}
})(current, previous);
Please mark this as the correct answer if I've answered your question. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2018 01:07 PM
This is pretty simple to do, but how you do it depends on where the list of CI sys_id values is and what format they are in. It also depends on when you want the CIs to be populated. Can you provide a bit more detail on that and I'll come up with a script for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2018 12:41 AM
Hi Mark,
thanks for the reply. Currently i have an incident being created via SOAP. as part of this a custom field in the form called Sysids is being populated with the Sys_id values i need in the format sys_id1,Sys_id2,Sys_id3. I then split this on the comma to get the individual values. Im looking to populate it as the incident is created.
If there is anything else i'm missing let me know
appreciate the help, thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2018 04:43 AM
Perfect. You'll want to do this in a business rule on the incident table with the following settings. I'm guessing on the field name 'u_sysids'. Just make sure that's correct!
Name: Add Affected CIs
When: After
Insert: True
Advanced: True
Condition: current.u_sysids.changes() && !current.u_sysids.nil();
Script:
(function executeRule(current, previous /*null when async*/) {
// Create 'Affected CIs from 'SysIDs' field
var cis = current.u_sysids.split(','); // Split the IDs into an array
// Iterate through the array
for (i=0; i<cis.length; i++) {
// Create a new 'Affected CI' record for each
var aci = new GlideRecord('task_ci');
aci.initialize();
aci.task = current.sys_id; // Associate to this record
aci.ci_item = cis[i];
aci.insert();
}
})(current, previous);
Please mark this as the correct answer if I've answered your question. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2018 01:45 AM
works perfectly thank you