Struggling to copy journal from INC to a RITM.

LRhodes
Tera Guru

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);
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Anurag Tripathi
Mega Patron
Mega Patron

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

-Anurag

Jaspal Singh
Mega Patron
Mega Patron

Replace

gr2.work_notes.setDisplayValue(notes);

with

gr2.work_notes.setJournalEntry(notes);

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you Ankur this has done the trick.

I've also added in the ability to copy the additional comments over but they're being added into the RITM separately. Any idea how they could be combined into one entry?

find_real_file.png