script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 11:10 AM
Hi All,
I am writing After Business Rule, and have created Problem ticket when Incident is "on hold".
In addition I want to update Incident Ticket as well, with Problem created. How we can achieve this?
Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 02:58 PM
If I am understanding correctly, when your Incident state changes to On Hold, you want to create a Problem record, and link that Problem record to the incident record.
If that is correct, your script should look something like this:
//Create a problem
var gr = new GlideRecord('problem');
gr.initialize();
gr.short_description = current.short_description;
gr.cmdb_ci = current.cmdb_ci;
var probRec = gr.insert();
gs.info ('Problem Ticket' + ' ' + gr.number);
//Connect the problem record back to this incident
current.problem_id = probRec;
I believe the script you have set up is working, but since you're not using current, and instead a GlideRecord query into Incident, you're updating a random record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 07:11 PM
update as this in after update BR
Ensure BR Condition is correctly configured -> State Changes to ON HOLD
Script:
var gr = new GlideRecord('problem');
gr.initialize();
gr.short_description = current.short_description;
gr.cmdb_ci = current.cmdb_ci;
var probRec = gr.insert();
gs.info ('Problem Ticket' + ' ' + gr.number);
//Connect the problem record back to this incident
current.problem_id = probRec;
current.setWorkflow(false);
current.update();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 08:24 PM
Hi @Ankur Bawiskar ,
Thanks for your inputs. This worked.
But, isn't it recommended not to use current.update() in business rules?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 08:42 PM
Glad to know that it worked
it's not recommended.
you can use before update BR then and current.update() not required
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader