Is there a way to populate Affected CIs in an incident Programtically using CI Sysids?

Acashman
Kilo Contributor

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

1 ACCEPTED SOLUTION

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!

View solution in original post

4 REPLIES 4

Mark Stanger
Giga Sage

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.

Acashman
Kilo Contributor

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

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!

Acashman
Kilo Contributor

works perfectly thank you