- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2022 02:34 AM
Hi all,
So a little overview of what we're trying to achieve. As things are we have a UI Action on Incidents to create a Request. This takes the user through the catalog - they select their item etc and then a REQ/RITM is created with the originating INC entered into the parent field on the REQ form (I'm sure this is all OOTB).
What I have been tasked to do is copy the journal from the Incident and put it into the RITM.
I have created a business rule that queries for the linked Incident and copies the journal. I then query the RITM to find the child to the REQ which is where I want to set the journal into. Below is the script I have running on the Request which isn't working. Any idea where I'm going wrong? It sounds like it should be fairly simple as all three records are linked.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('incident');
gr.addQuery('number', current.parent);
gr.query();
if(gr.next()){
var notes = gr.work_notes.getJournalEntry(-1);
var gr2 = new GlideRecord('sc_req_item');
gr2.addQuery('request', current.number);
gr2.query();
if (gr2.next()){
gr2.work_notes.setDisplayValue(notes);
}
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2022 02:43 AM
Hi,
I think the parent field is reference so you should query with sys_id and not number
I consider since your BR is on sc_request you should query by getting the sys_id of req
Changes in bold
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', current.parent);
gr.query();
if(gr.next()){
var notes = gr.work_notes.getJournalEntry(-1);
var gr2 = new GlideRecord('sc_req_item');
gr2.addQuery('request', current.sys_id);
gr2.query();
if (gr2.next()){
gr2.work_notes = notes;
gr2.update();
}
}
})(current, previous);
Regards
Ankur
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-24-2022 02:39 AM
Hi,
Use this
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('incident');
gr.addQuery('number', current.parent);
gr.query();
if(gr.next()){
var notes = gr.work_notes.getJournalEntry(-1);
var gr2 = new GlideRecord('sc_req_item');
gr2.addQuery('request', current.number);
gr2.query();
if (gr2.next()){
gr2.work_notes = notes;
gr2.update();
}
}
})(current, previous);
-Anurag

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2022 02:40 AM
Replace
gr2.work_notes.setDisplayValue(notes);
with
gr2.work_notes.setJournalEntry(notes);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2022 02:43 AM
Hi,
I think the parent field is reference so you should query with sys_id and not number
I consider since your BR is on sc_request you should query by getting the sys_id of req
Changes in bold
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', current.parent);
gr.query();
if(gr.next()){
var notes = gr.work_notes.getJournalEntry(-1);
var gr2 = new GlideRecord('sc_req_item');
gr2.addQuery('request', current.sys_id);
gr2.query();
if (gr2.next()){
gr2.work_notes = notes;
gr2.update();
}
}
})(current, previous);
Regards
Ankur
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-24-2022 06:55 AM