- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 08:43 AM
Hi all,
How can I add comments to a record, for example in the 'Incident' table, via a Scripted REST API?
What is the right method?
I tried PATCH and PUT and they are working for every other field.
I read that the 'comments' field is special as it relates to another table but I still cannot find a way to post a comment.
Thank you in advance for your help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 11:58 PM
In REST API Explorer you can create examples of REST Messages.
Here's an example where I create a PUT message that updates the specified incident with Additional comments "Hello".
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://your_instance.service-now.com/api/now/table/incident/your_sys_id');
request.setHttpMethod('PUT');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json');
request.setRequestBody("{\"comments\":\"Hello\"}");
var response = request.execute();
As you can see the body is set to "{\"comments\":\"Hello\"}"
There are many ways to write the REST message, but technically if you've been able to update any other fields, then comments should work just as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 09:07 AM
There shouldn't be anything special about it when updating.
Yes, comments and work_notes are stored in a separate table and work in a special way, but you should be able to update them with a regular put message.
How do you build your message? How does it look like?
I made this as an example with the built in REST Api Explorer with PUT method and it updated an incident without issues.
request.setRequestBody("{\"comments\":\"Hello\"}");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 10:40 PM
Hi,
Thank you for your reply.
Where is this defined exactly? Could you please provide a screenshot?
Thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 11:58 PM
In REST API Explorer you can create examples of REST Messages.
Here's an example where I create a PUT message that updates the specified incident with Additional comments "Hello".
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://your_instance.service-now.com/api/now/table/incident/your_sys_id');
request.setHttpMethod('PUT');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json');
request.setRequestBody("{\"comments\":\"Hello\"}");
var response = request.execute();
As you can see the body is set to "{\"comments\":\"Hello\"}"
There are many ways to write the REST message, but technically if you've been able to update any other fields, then comments should work just as well.