How an I cancel a change request using REST? Is it just a matter of updating the 'state'? If so, what is the 'state' value for cancelled? What other fields do I need to update in order to cancel th change request?

drewtarr
Giga Contributor

I am trying to cancel th change requestwith the following fields:

      current_time = time.strftime("%Y-%m-%d %H:%M:%S")

      userID = raw_input("Enter User ID (LDAP): ")

      close_notes = "TEST CHANGE - CANCELLED"

      closed_by = userID

      payload['state'] = 8

      payload['closed_at'] = current_time

      payload['close_notes'] = close_notes

      payload['closed_by'] = closed_by

When I make a REST PUT call, I get a 200 status back.

However, the only field that appears to be changed is the 'close_notes'

What am I missing?

5 REPLIES 5

Shiva Thomas
Kilo Sage

Hi Drew,



The value you are looking for the state is '4'.


The Out of the Box business rules should set the other relevant value correctly (closed date, closed by, updated date, updated by...).


If you right click on the label name of a choice field you can display/edit all the value via the "Show Choice List" option.


Capture d



Capture d



I don't understand why you specify "payload" for some of your field names. Remove them and simply use something like state = '8'.


I think you can remove/ignore closed_by, closed_at, closed_by.



Your PATCH payload should be: {"state":"4","close_notes":"My close note"}


You can try this in the REST Explorer available in your instance.


Capture d


Capture d



The existing business rules will do the rest. ^_^


Hi Shiva, isn't the value should be an integer (4) rather than a string ('4')?


Hi Regina,



Choice fields in ServiceNow are always strings. See choices available on Category.


State values are not numeric, but for ServiceNow (int)4 considers the same string (4).


Gopi46
Kilo Contributor

Hi Shiva,

My requirement to cancel the REQ Sample Request(REQ0213682) thru Java API.

I am using PATCH API as mentioned above with state 4 to cancel the request by selecting the SYS_ID from SC_REQUEST table. Why I am selecting the table as SC_REQUEST because its a REQ item not the change item. 

Although I am getting the response as 200, request is not getting changed to cancelled and it is still in approval pending. 

My ServiceNow rest end point is 

PATCH https://mubdev.service-now.com/api/now/table/{tableName}/{sys_id}

table Name: sc_request