Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Copy RITM Comments (Including Approval Comments) to SC Task with correct order and user information

Aman Sharma1
Tera Contributor

Hi All,

 

I have requirement where i need to copy all comment from an RITM - Including comments added during approvals - to the related SC Task. The goal is to ensure that all comments made before the approval are reflected on the SC Task once it is created.

I'm currently able to copy the comments successfully. However, I'm facing 2 issues:

 

1 - Comments Sequence/order on the SC Task does not match the original order from the RITM.

2- User - who made the comment is not getting copied correctly - it often shows the wrong user or the same name user for all comments.

 

Can anyone suggest the best way to maintain the correct the order and created by user when copying RITM comments to SC Task

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Aman Sharma1 

share your existing scripts and screenshots.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Aman Sharma1
Tera Contributor

AmanSharma1_1-1762796000244.png

 

I am trying this way to Insert Business rules for copy comment and fetch the created by user from sys journal table. Can you please look whether code is correct or suggest me any other alternative for it, which could work for it.

@Aman Sharma1 

why not directly copy and why to use sys_journal_field?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Its_Azar
Tera Guru
Tera Guru

Hi there @Aman Sharma1 

 

The best approach is to pull comments from the sys_journal_field table instead of relying on current comments directly, since that preserves both order and user data. You can query sys_journal_field for the RITM (element_id = current.sys_id) and sort by sys_created_on to maintain the right sequence.

 

like e this

var comments = new GlideRecord('sys_journal_field');
comments.addQuery('element_id', ritmSysId);
comments.addQuery('element', 'comments');
comments.orderBy('sys_created_on');
comments.query();
while (comments.next()) {
    var note = new GlideRecord('sys_journal_field');
    note.initialize();
    note.name = 'sc_task';
    note.element_id = taskSysId;
    note.element = 'comments';
    note.value = comments.value;
    note.sys_created_by = comments.sys_created_by;
    note.insert();
}
☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG