Need to copy worknotes from incident to incident tasks

Anjaneyulu1
Giga Contributor

Hii All,

I have written script like this,

when to run - after update

condition - work notes changes

script -

var inc = new GlideRecord('incident_task');
inc.addQuery('incident.sys_id', current.sys_id);
inc.query();
while (inc.next()) {
inc.work_notes = current.work_notes.getJournalEntry(1);
inc.update();
}

my script is not working but in place of worknotes if i place comments then it is working.

i don't know why it is happening like that.

please help me where i have written mistake here.

 

1 ACCEPTED SOLUTION

Hi Anji,

I just tested again and it is working:

find_real_file.png

find_real_file.png

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

If this answer is helpful please mark correct and helpful!

Regards,
Chris Perry

View solution in original post

20 REPLIES 20

Gaurav Shirsat
Mega Sage

Hello

Can You Please try below code:- before/update

var grInc= new GlideRecord('incident_task');
if(grInc.get('incident',current.getUniqueValue()))
{
grInc.work_notes=current.work_notes.getJournalEntry(1);
grInc.update();

}

Mark my Response as Correct or Helpful, if you find it Appropriate.
Gaurav Shirsat : ServiceNow Community MVP 2022
https://www.linkedin.com/in/gauravshirsat/

 

Hii Gaurav,

I have tried your code but still it is showing like that only.

find_real_file.png

 

Hello

Could You Please Check is there any other business rule working in your system?

Try to add script debugger in your script.

I tried in my PDI. it is working.

find_real_file.png

find_real_file.png

Can You Debug the Script by below using below screenshot:-

Click on the 1st line of code as stated below:

find_real_file.png

click on the icon mentioned and check one by one, is there any BR with current.update();

find_real_file.png

Mark my Response as Correct or Helpful, if you find it Appropriate.
Gaurav Shirsat : ServiceNow Community MVP 2022
https://www.linkedin.com/in/gauravshirsat/

 

 

chsumit
Kilo Expert

Hi,

Try Before Update BR with below details.

Table: Incident

Before Update

When Worknotes Changes

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

// Add your code here
var grIncTask = new GlideRecord('u_incident_task');
//grIncTask.addQuery('u_incident',current.sys_id);
grIncTask.addEncodedQuery('u_incident='+current.sys_id+'^stateNOT IN5,6');
grIncTask.addActiveQuery();
grIncTask.query();

while(grIncTask.next())
{
grIncTask.work_notes = current.work_notes;
grIncTask.update();
}
})(current, previous);

 

//Update the query accordingly.

Thanks,

Sumit

Hii Sumit,

i have tried your code still worknotes coming 3times.

find_real_file.png