- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2023 02:22 AM
Hi Community, I have written a BR to change state of related incidents to resolved when problem is resolved and to copy the fix notes field from problem to resolution notes in associated incidents. But it is not working can anyone please give the solution for this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2023 04:23 AM
Hi @SanthoshKumar R,
Try this updated scripts and your business rule condition should state changes to resolved:
(function executeRule(current, previous /*null when async*/ ) {
var problem = current.getUniqueValue();
var inc = new GlideRecord('incident');
inc.addQuery('problem_id', problem);
inc.query();
while (inc.next()) {
inc.setValue('state', '6');
inc.setValue('close_notes', current.description);
inc.setValue('close_code', 'Resolved by problem: ' + current.number);
inc.setWorkflow(false);
inc.autoSysFields(false);
inc.update();
}
})(current, previous);
If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2023 02:30 AM
inc.update(); is missing.
Try below code:
function executeRule(current, previous /*null when async*/) {
// Add your code here
var problem=current.sys_id;
var inc=new GlideRecord('incident');
inc.addQuery('problem_id',problem);
inc.query();
while(inc.next())
{
inc.setValue('state','6');
inc.setValue('close_notes',current.fix_notes);
inc.update();
}
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2023 02:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2023 03:02 AM
Hi @SanthoshKumar R Can you please try with the below script.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var problem = current.sys_id;
var inc = new GlideRecord('incident');
inc.addQuery('problem_id', problem);
inc.query();
while (inc.next()) {
inc.state = '6'; // Update the state using direct assignment
inc.close_notes = current.fix_notes;
inc.close_code='Resolved by problem';// Update the close notes
inc.update(); // Update the incident record
}
})(current, previous);
But the issue here in the above script is that Fix notes you are copying from Problem might cause an issue due the HTML data type when updating same to the Incident close notes it will be updated in HTML format.
Cheers, hope that helps
Eswar Chappa
*** Please mark as "Correct" or "Helpful" as appropriate ***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2023 03:12 AM
Same issue is repeated when trying to copy description field instead of ix_notes