Duplicate comment getting added

Diksha_Tiwari 1
Tera Contributor

Hi Folks,

 

So I want to add 2 comments to a case from a script include. Below is the code:

 

 var reason = "Does not satisfy the project activities";
 var comment = "test NOTA comment";
 var taskGr1 = new GlideRecord('sn_wsd_case_workplace_case');
 taskGr1.addQuery('sys_id', 'caseSys_ID'); // sysID of case
 taskGr1.query();
 if (taskGr1.next()) {
     if (comment.toString() !== '') {
         taskGr1.comments = reason.toString() + '-' + comment.toString();
         taskGr1.close_notes = reason.toString() + '-' + comment.toString();
     }
     taskGr1.variables.snc_reason = reason.toString();
     taskGr1.comments = "Workplace team selected 'None of the Above' from space option.";
     taskGr1.comments = "Comment 3";
     taskGr1.update();
 }
 
Output of above is coming as below:
Diksha_Tiwari1_0-1739190104649.png

 

One additional comment is getting added , which is combination of below three comments which I am adding separately. How can I fix this? I don't want the combined comment.

 

Any suggestion would be appreciated!.

 

Thanks & Regards.

Diksha

1 ACCEPTED SOLUTION

Mark Manders
Mega Patron

Please share all logic, not just the script include... How is it called? 

Next to that: comments are added and written to the sys_journal_field table. If you want to add two separate comments to the same ticket (process wise that doesn't really make sense), you will have to have 2 updates to the record to update them to the sys_journal_field table and with that, show them in the activity log.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Diksha_Tiwari 1 

where have you written this script? is this a business rule?

what type of business rule?

what's your business requirement?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Mark Manders
Mega Patron

Please share all logic, not just the script include... How is it called? 

Next to that: comments are added and written to the sys_journal_field table. If you want to add two separate comments to the same ticket (process wise that doesn't really make sense), you will have to have 2 updates to the record to update them to the sys_journal_field table and with that, show them in the activity log.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Yeah, thank you for the insight. I did 2 updates on record. It worked as expected now.

Thank you for helping!