How to close Work Order using REST API

viktormay
Kilo Contributor

Hello.

I'm trying to close work order via REST API explorer (for testing) .

Using dedicated user for that. With all the roles (admin). Work orders are created with that user also.

I try to use these fields in PUT request to wm_order table:

{"work_notes":"test","state":"3","u_close_code":"1"}

PUT https://instance.com/api/now/table/wm_order/HereIsSysId

I get 200 OK.

The problem is that everything updates but state.

I can't change it at all via PUT. Other fields like close notes modified just fine.

What should i look into?

UPDATE: Work Order Tasks doesnt update State as well with PUT

12 REPLIES 12

I can't close Work Order in UI. No buttons for that action.


Yes, usually i close WO through Work Order Task.


And i could close Work Order Task but how can i get Work Order Tasks IDs which related to a specific Work Order?


GET for a specific Work Order doesn't provide Tasks IDs.


I think you would have to write a REST scripted action for this.   Feed it the sys_id of the Work Order, query the tasks, close them, then close the work order.   You cannot do in REST what you cannot do in the UI, generally speaking.   REST calls are simply HTTP calls to the system.


Allright. This is the part where i stuck:


>Feed it the sys_id of the Work Order, query the tasks



No tasks in response!


And i tried to change task state with PUT - nothing happens. Only other fields are filled


Yeah, it has to be a scripted REST api:



find_real_file.png



You would set an input parameter (sys_id), then define the method, and do something with that parameter in your script.   For an example, look at List Query in the scripted table.


Thanks. But i think that if i can't close WO and WOT with REST API Explorer i won't be able to close it with Scripted REST API too