copy from inciden task 'close notes' to parent incident worknotes

tushar_ghadage
Tera Contributor

Hi All , 

I am trying to copy close notes from incident task (when its close complete) to parent incident record in worknotes.

 

here is the before update with condition close notes changes business rule is used: 

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var lastWorkNote = current.close_notes.getJournalEntry(-1);

    var parentInc = new GlideRecord('incident');
    parentInc.addQuery('sys_id', current.parent_incident);
    parentInc.query();

    if (parentInc.next()) {
        parentInc.work_notes = lastWorkNote;
        parentInc.update();
    }

})(current, previous);
 
but its not getting copied as expected , please help me out !!
17 REPLIES 17

_Gaurav
Kilo Sage

Hi @tushar_ghadage 

Can you try the below code on incident_task table in before update BR the condition is State change to Closed complete

var lastWorkNote = current.close_notes.toString();

    var parentInc = new GlideRecord('incident');
    parentInc.addQuery('sys_id', current.incident);
    parentInc.query();

    if (parentInc.next()) {
        parentInc.work_notes = lastWorkNote;
        parentInc.update();
    }

 

Please mark this as a solution and helpful if this resolves your query.

Thanks!



 

Rohit  Singh
Mega Sage

Hi @tushar_ghadage ,

 

Your approach is fine but just few mistakes. 

  1. var lastWorkNote = current.close_notes.getJournalEntry(-1);   /// This is just a string field so you don't have to write getJournalEntry. This is use for journal field like work_notes.
  2. parentInc.addQuery('sys_id', current.parent_incident);    //  The field name for incident reference field is incident in incident task task table.

You can just use 5 lines of code.

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here

	var close_info = current.close_notes.toString();   // get the value of close notes
	var gr_inc = new GlideRecord("incident");
	gr_inc.get("sys_id",current.incident);
	gr_inc.work_notes = close_info;
	gr_inc.update();

	

})(current, previous);

 

If my response helped, please hit the Thumb Icon and accept the solution so that it benefits future readers.

 

Regards,
Rohit

 

Hi @tushar_ghadage ,

 

Can you tell what's the issue you are facing? 

Make sure your BR is in Inicdent_task table and condition should be State Changes to "Closed Complete"

 

Regards,

Rohit

Chaitanya ILCR
Kilo Patron

Hi @tushar_ghadage 
Try this

(function executeRule(current, previous /*null when async*/ ) {

    if (current.getValue('incident')) {
        var incGr = current.incident.getRefRecord();
        incGr.work_notes = current.getValue('close_notes');
        incGr.update();
    }

})(current, previous);

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya