- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2016 05:08 AM
Hi Experts,
In problem form, there is a related list of its child incidents derived from each problem. I have created a new Reference field "Related Incidents" in the problem form. I need to fetch all incidents for each problem by applying Onload client script querying the incident table, such that all the values in the related list are populated in this field seperated by comma.
Could anyone please me guide on this?
Thanks,
Rathika.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 01:06 PM
Hi Rathika,
Here's your business rule for maintaining the u_rel_tasks field if you decide not to go with hierarchical lists. There's one inefficiency to this script in that it runs for as many times as you add or remove incidents from the related list. If you add 4 incidents, it runs 4 times (likely reproducing the same values in many cases.) It's not perfect but it works.
When: After
Table: Incident
Active: true
Advanced: true
Insert: true
Update: true
Condition: current.problem_id.changes()
Script:
(function executeRule(current, previous /*null when async*/) {
var parentProblemID = '';
//This function will be automatically called when this rule is processed.
var pr = new GlideRecord('problem');
// If adding it to the list, then use the current.problem_id
// Otherwise, if it's blank, use the previous value
if (current.getValue('problem_id'))
parentProblemID = current.getValue('problem_id');
else
parentProblemID = previous.getValue('problem_id');
if(pr.get(parentProblemID)) {
gs.log('inside if ... ');
var incArr = [];
var inc = new GlideRecord('incident');
inc.addQuery('problem_id', parentProblemID);
inc.query();
while (inc.next()) {
incArr.push(inc.getValue('sys_id'));
}
pr.u_rel_tasks = incArr.join(',');
pr.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 01:06 PM
Hi Rathika,
Here's your business rule for maintaining the u_rel_tasks field if you decide not to go with hierarchical lists. There's one inefficiency to this script in that it runs for as many times as you add or remove incidents from the related list. If you add 4 incidents, it runs 4 times (likely reproducing the same values in many cases.) It's not perfect but it works.
When: After
Table: Incident
Active: true
Advanced: true
Insert: true
Update: true
Condition: current.problem_id.changes()
Script:
(function executeRule(current, previous /*null when async*/) {
var parentProblemID = '';
//This function will be automatically called when this rule is processed.
var pr = new GlideRecord('problem');
// If adding it to the list, then use the current.problem_id
// Otherwise, if it's blank, use the previous value
if (current.getValue('problem_id'))
parentProblemID = current.getValue('problem_id');
else
parentProblemID = previous.getValue('problem_id');
if(pr.get(parentProblemID)) {
gs.log('inside if ... ');
var incArr = [];
var inc = new GlideRecord('incident');
inc.addQuery('problem_id', parentProblemID);
inc.query();
while (inc.next()) {
incArr.push(inc.getValue('sys_id'));
}
pr.u_rel_tasks = incArr.join(',');
pr.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2016 10:00 PM
Hi Tomasi,
Thanks for your great help
It is working perfectly now. I would prefer running the BR as this output is accepted for my project rather than the hierarchical lists. However, both are useful and the hierarchy method can be implemented for lists in the future projects as well.
Thanks,
Rathika.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2019 10:31 PM
Hi Thomas I'm new to servicenow,I have a requirement where on the incident form for open tickets once the short description is given I should get a pop up box which should give list of knowledge articles with similar short description by searching for keywords.can you please suggest me in detail what need to be done?
Hope I get response quickly