Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Copy worknotes from IncidentTask to Incident

jui
Tera Contributor

Hi All,

 

I have below requirement.

Copy worknotes from IncidentTask to Incident.

I have write BR for this but BR is not working please let me know what is issue in my BR. (BR is on After Insert and Update)

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

    // Add your code here
    var ab = current.work_notes;
    var gr = new GlideRecord("incident");
    gr.addQuery('number',current.incident);
    gr.query();
   
    gr.work_notes=ab;
    gr.update();


})(current, previous);
3 REPLIES 3

tharun_kumar_m
Mega Guru

Hi Jui,

 

current.incident will give you the sys_id of the incident. So, please update your code as below.

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

    // Add your code here
	gs.log(current.incident+" "+current.work_notes);
    var gr = new GlideRecord("incident");
    gr.addQuery('sys_id',current.incident);
    gr.query();
	while(gr.next()){

		gr.work_notes=current.work_notes.getJournalEntry(1);
		gr.update();
	}

})(current, previous);

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumbs up.

 

Best regards,

Tharun Kumar

bubuprasadswain
Tera Guru

@jui Please use below code snippet:

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

    // Add your code here
    var incTask = current.work_notes.getJournalEntry(1);    
   
    var rec = new GlideRecord('incident');
    rec.addQuery('sys_id',current.incident);
    rec.addActiveQuery();
    rec.query();
    if (rec.next()) {

                rec.work_notes = 'Work notes copied from incident task: '+incTask;
                rec.update();
                        }
                       
}      

)(current, previous);

 

AshishKM
Kilo Patron
Kilo Patron

Hi @jui ,

You need to write update BR [ after ] on Incident Task ( incident_task ) with condition on worknotes changes.

AshishKMishra_0-1712927254273.png

 

You need only one line of code in BR. Incident Task has parent column which hold the incident's sys_id so we dont need to again glide on incident table.

AshishKMishra_1-1712927525182.png

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution