How to get the sys_id for sysapproval_approver table from a particular change request from REST API

Anshuman7
Tera Contributor

Hi I want to get the sys_id for sysapproval_approver table to approve / reject a change . In order to do that can I get the sys_id from the change request using REST API . I only have the change request number , by using that I need to get the all sys_id (approval) for that change 

6 REPLIES 6

Anshuman7
Tera Contributor
 "sysapproval": {
        "link": "https://dev121535.service-now.com/api/now/table/task/02cd7552db252200a6a2b31be0b8f5e0",
        "value": "02cd7552db252200a6a2b31be0b8f5e0"
      }

How I will query the sysapproval.value as this is not working

ChrisBurks
Mega Sage

If I read your question correctly, you're trying to get all the sys_ids for approvals (sysapproval_approver) records from a change request sys_id using the REST API?

If that is correct then yes this is possible. The sys_id of the change request would be present in the "Approval for" (sysapproval) field  or the "Approving" (document_id) field of the sysapproval_approver record since it's a task.

You'll also want to leverage the "source_table" field which will contain the table name of the record needing a approval.

So, in your REST API call use document_id or sysapproval field as a encoded query for the sysparm_query parameter. You should be able to use the REST API Explorer application that comes with every instance. It's similar to something like POSTMan where it helps you test out the REST  API and gives you information on how to build your call.

Here are some steps to try:

  • Navigate to a list view of the sysapproval_approver table
  • Filter the list to display the desired record(s)
  • Right click on the last crumb of the filter breadcrumb
  • Select to copy the query
  • Navigate to the REST API Explorer by typing in REST API EX.... in the left filter navigator
  • Click on the REST API Explorer module
  • In the REST API Explorer Form make sure these values are selected for the fields
    • Namespace: now
    • API Name: Table API
    • API Version: "The version you desire to use"
    • At the left make sure the Arrow is point at the "Retrieve records from a table (GET)" option
    • Under the "Prepare Request" section select Approval [sysapproval_approver] for the tablename
    • Under "Query parameters" paste in the query you copied from the filter breadcrumbs in the sysparm_query field
    • Since this tool is just for testing purposes it has the result limit set to one and only gives you another choice of returning 10. Change the sysparm_limit to 10 if you want to see multiple records (if they exist for your query)
    • Now click the "Send" button at the bottom

If everything is done correctly you should see results with information of all records meeting the query.

You should also see what the endpoint and parameters should look like when sending. There are also links that will trigger popups to show you how to script this in ServiceNow, cURL, Python, Ruby, Javascript, Perl, and Powershell

Here's a glimpse using an encoded query I copied from a filtered list view sysapproval=e2cdf552db252200a6a2b31be0b8f57f

- Navigating to and getting list view query

find_real_file.png

 

- Navigating to REST API Explorer and populating necessary fields

find_real_file.png

 

Full REST API Explorer view after sending call (also attached in case it doesn't render here)

find_real_file.png

 

Thanks It is working . 

It looks good.

the output of API "api/now/table/sysapproval_approver?sysparm_query=sysapproval=" returns the document id like below:

<document_id>
<link>https://.service-now.com/api/now/table/change_request/625cfc718708___5fb10273cbb35ca</link>
<value>625cfc718708___5fb10273cbb35ca</value>
</document_id>
<sys_id>07710a061b___5628ce54bcbc5</sys_id>
<sys_updated_by>VIACHESLAV.@.COM</sys_updated_by>
<register_account/>
<sys_created_on>2025-03-04 11:23:34</sys_created_on>
<iteration>1</iteration>
<state>requested</state>
<approval_source/>
<sys_created_by>VIACHESLAV.@.COM</sys_created_by>

Question: can the sys_id parameter be used to approve the change request by using the service account? For instance, the patch request:

https://.service-now.com/api/now/table/sysapproval_approver/07710a061b___5628ce54bcbc5
{
    "state": "approved"
}

In my case the backend returns 200, but the "state" has not been changed:
      "state": "requested"

Could you please clarify if there is a chance to use the service account to approve the change request in respect of application user?

BR, Slava