How to check if a comment or work notes exists on a record?

Brianlion
Giga Contributor

I'm trying to pull comment data from a third party app via REST and insert it into incident records in snow and I was wondering how to update the activity stream with new comments. Currently, when creating a record I will just set the comment I got from the third party app. But if I wanted to update the record and see if any new comments were made in the third party app, I figured I would have to query the sys_journal_field table and check to see if the comment already exists and if it doesn't I should update the activity stream with my new comments I read that querying the sys_journal_field table could be overkill since it could have so many entries. Is this the correct way of doing things or is there a better way?

 

Example of what I'm doing:

var gr = new GlideRecord('sys_journal_field');

gr.addQuery('value', responseObj.Response.ListOfServiceRequest.ServiceRequest[i].ListOfLa311ServiceRequestNotes.La311ServiceRequestNotes[k].Comment);

gr.query();

if(!gr.next()){

gr.comment = responseObj.Response.ListOfServiceRequest.ServiceRequest[i].ListOfLa311ServiceRequestNotes.La311ServiceRequestNotes[k].Comment);

}

2 REPLIES 2

Prateek kumar
Mega Sage

Shouldn't it be?

var gr = new GlideRecord('sys_journal_field');

gr.addQuery('value', responseObj.Response.ListOfServiceRequest.ServiceRequest[i].ListOfLa311ServiceRequestNotes.La311ServiceRequestNotes[k].Comment);

gr.query();

if(!gr.next()){

gr.value = responseObj.Response.ListOfServiceRequest.ServiceRequest[i].ListOfLa311ServiceRequestNotes.La311ServiceRequestNotes[k].Comment);

}


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Brianlion,

 

You can GlideRecord the target Table (for ex: Incident) to fetch work notes or comments and then apply the logic to do the matching check. 

gr.comments.getJournalEntry(-1);

gr.work_notes.getJournalEntry(-1);

Reference:

https://docs.servicenow.com/administer/field_administration/reference/r_CodeGetJrnalFldContsIntoAnAr...

 

-Pradeep Sharma