Not display all affected CIs in custom field, created in Incident record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2024 01:48 PM
Request your assistance in reviewing the following Business Rule applied after "Insert" and "Update". The objective is to display the ci_item names affected with the Incident Record in custom field named as "List of associated CIs:" in the incident form.
Name: affectedCIsIncident
Table: CIs Affected[task_ci]
Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2024 05:00 PM
The issue is likely with your non-standard use of get, combined with the use of while. What are you really trying to accomplish getting the previous task. Is current task ever blank? Try something more like this:
(function executeRule(current, previous /*null when async*/) {
var ciList = [];
var gr=new GlideRecord('incident');
if (gr.get(current.task) {
var citems=new GlideRecord('task_ci');
citems.addQuery('task', current.task);
while (citems.next()) {
ciList.push(citems.ci_item.getDisplayValue());
}
gr.u_list_of_associated_cis=ciList.join(', ');
gr.update();
}
})(current, previous);
If there's a case where current.task is blank, incorporate that with addQuery lines. You can also troubleshoot this by adding log lines to see what is happening while the script is running.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2024 10:30 PM
I had shared the the image of my output as attachment, kindly check, I want to display the name of CI items in custom field, if I will add CI item under "Affected CIs" section, then automatically my custom field got updated. If I remove the CI item from the same section then automatically my custom field got updated.
To conclude, on removing and adding CIs from "Affected CIs" section my custom field automatically got updated with the fresh list of CIs. that's why I used both previous and current in my script. My script is running but one CI is always got missed in and rest of the CI names are displaying. My custom field names as" List of associated CIs." Kindly assist.