- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2018 02:45 AM
HI,
Looking for some assistance please:
On my incident form I have a custom field called Component Ci(s) (type List - referencing cmdb_rel_ci) basically this field is present so any Configuration item that has a relationship with the Technical System (also present on the Incident form) is selectable. Please see screen shot below
As you can see from the screenshot when you click on the i icon next to the Component Ci selected, the Relationship record displays.
What I am looking to do is write a Business Rule to initialize a record on the task_ci table (Affected Ci) so the Child of the relationship record is written to the ci_item column on the task_ci table.
Here is what I have tried but I don't think the scripting is correct:
(function executeRule(current, previous /*null when async*/) {
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('sys_id', current.u_component_ci);
rel.addQuery('type', '47e4a6424fcb5640c9ca69d18110c7bf');
rel.query();
var taskci = new GlideRecord('task_ci');
taskci.initialize();
taskci.ci_item.setDisplayValue(rel.child);
taskci.setValue('task', current.sys_id);
taskci.insert();
})(current, previous);
Right now when this script runs a record is created on task_ci as you can see below but the ci_item is not being populated correctly
I hope it is clear what I am trying to do. Any assistance would be most appreciated
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2018 02:30 AM
The below script will clear the relationships for the current task and then repopulate with the ones in the component CI field.
var gr = new GlideRecord('task_ci');
gr.addQuery('task', current.sys_id);
gr.query();
gr.deleteMultiple();
var componentCI = current.u_component_ci.split(',');
for(var i=0; i< componentCI.length; i++){
var rel = new GlideRecord('cmdb_rel_ci');
if(rel.get(componentCI[i])){
var taskci = new GlideRecord('task_ci');
taskci.initialize();
taskci.ci_item = rel.getValue('child');
taskci.task = current.sys_id);
taskci.insert();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2018 02:30 AM
The below script will clear the relationships for the current task and then repopulate with the ones in the component CI field.
var gr = new GlideRecord('task_ci');
gr.addQuery('task', current.sys_id);
gr.query();
gr.deleteMultiple();
var componentCI = current.u_component_ci.split(',');
for(var i=0; i< componentCI.length; i++){
var rel = new GlideRecord('cmdb_rel_ci');
if(rel.get(componentCI[i])){
var taskci = new GlideRecord('task_ci');
taskci.initialize();
taskci.ci_item = rel.getValue('child');
taskci.task = current.sys_id);
taskci.insert();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2018 02:52 AM
David,
You are simply a wizard my friend. Thank you so much this is working great. I really appreciate your time working on this with me.
Cheers
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2018 03:08 AM
You're welcome 🙂