How to make the REST call to create a new Work Order Task that is child to an existing Work Order?

scha
Kilo Explorer

We are in version: Eureka and below is our REST call -

URI

https://<service-now instance>/api/now/table/wm_task

HTTP Action

POST

JSON Request

{

"parent": "WO0010003",

"short_description": "wm task insert test",

"comments": "wm task insert test"

}

This request creates the new task but does not associate the new WOT… task to my desired Work Order - WO0010003. What are we missing?

Thanks!

5 REPLIES 5

ChrisRoyer
Kilo Guru

So if you show XML on that record you will more than likely see that the parent actually has what you entered in, rather than the sys_id of that record. I believe you have to set sysparm_input_display_value=true


Here's the REST call I make to create the Work Order first


https://<service-now instance>/api/now/table/wm_order


POST


{


  "short_description": "wm task insert test"


}


this creates the record in work order table - WO0010028



When I make a call -



URI


https://<service-now instance>/api/now/table/wm_order?sysparm_display_value=true&sysparm_query=numbe...  


HTTP Action


GET


Response


<response><result><skills/><estimated_end/><upon_approval>Proceed to Next Task</upon_approval><location/><expected_start/><close_notes/><auto_dispatch>false</auto_dispatch><impact>3 - Low</impact><urgency>3 - Low</urgency><correlation_id/><billable>false</billable><priority>4 - Low</priority><group_list/><description/><sys_domain><display_value>global</display_value><link>https://<service-now instance>/api/now/table/sys_user_group/global                                                   </link></sys_domain><delivery_plan/><sys_mod_count>0</sys_mod_count><work_notes_list/><sla_suspended>false</sla_suspended><follow_up/><template/><closed_at/><sla_due>UNKNOWN</sla_due><delivery_task/><sys_updated_on>2015-11-12 13:17:38</sys_updated_on><parent/><work_end/><number>WO0010028</number><closed_by/><work_start/><business_duration/><activity_due>UNKNOWN</activity_due><correlation_display/><company/><active>true</active><due_date/><initiated_from/><assignment_group/><caller/><qualification_group/><knowledge>false</knowledge><made_sla>true</made_sla><comments_and_work_notes/><state/><user_input/><sys_created_on>2015-11-12 13:17:38</sys_created_on><approval_set/><reassignment_count>0</reassignment_count><opened_at>2015-11-12 13:17:37</opened_at><short_description>wm task insert test</short_description><order/><expected_end/><sys_updated_by>admin</sys_updated_by><upon_reject>Cancel all future Tasks</upon_reject><sla_suspended_on/><approval_history/><calendar_duration/><work_notes/><approval>Not Yet Requested</approval><sys_id>4ffbee7f0fe7ca009b6fc5bce1050e6c</sys_id><sys_created_by>admin</sys_created_by><assigned_to/><cmdb_ci/><opened_by><display_value>System Administrator</display_value><link>https://<service-now instance>/api/now/table/sys_user/6816f79cc0a8016401c5a33be04be441</link></opened_by><sys_class_name>Work Order</sys_class_name><watch_list/><escalation>Normal</escalation><contact_type>Phone</contact_type><time_worked/><comments/></result></response>



Then when I make the call to enter Work Order Task


URI


https://<service-now instance>/api/now/table/wm_task?sysparm_input_display_value=true


HTTP Action


POST


JSON Request


{


"parent": "WO0010028",


"short_description": "wm task insert test"


}



Still I get parent as ""


...


sys_updated_on: "2015-11-12 21:33:35"


parent: ""


work_end: ""


number: "WOT0010098"


...



Then when I make the call to enter Work Order Task


URI


https://<service-now instance>/api/now/table/wm_task?sysparm_display_value=true&sysparm_query=number...


HTTP Action


POST


Response


<response><result><skills/><estimated_end/><upon_approval>Proceed to Next Task</upon_approval><location/><expected_start/><close_notes/><auto_dispatch>false</auto_dispatch><window_start>2015-11-12 13:33:35</window_start><impact>3 - Low</impact><urgency>3 - Low</urgency><correlation_id/><expected_travel_start/><routing_in_progress>false</routing_in_progress><group_list/><description/><priority>4 - Low</priority><sys_domain><display_value>global</display_value><link>https://<service-now instance>/api/now/table/sys_user_group/global                                                   </link></sys_domain><delivery_plan/><sys_mod_count>0</sys_mod_count><work_notes_list/><window_end/><is_fixed_window>false</is_fixed_window><follow_up/><template/><closed_at/><sla_due>UNKNOWN</sla_due><acknowledged_on/><delivery_task/><sys_updated_on>2015-11-12 13:33:35</sys_updated_on><parent/><work_end/><number>WOT0010098</number><closed_by/><cloned_from/><estimated_work_duration>1 Hour</estimated_work_duration><work_start/><business_duration/><actual_travel_duration/><activity_due>UNKNOWN</activity_due><correlation_display/><company/><active>true</active><due_date/><assignment_group/><knowledge>false</knowledge><made_sla>true</made_sla><comments_and_work_notes/><state/><approval_set/><sys_created_on>2015-11-12 13:33:35</sys_created_on><user_input/><reassignment_count>0</reassignment_count><dispatch_group/><under_warranty>false</under_warranty><opened_at>2015-11-12 13:33:35</opened_at><order/><short_description>wm task insert test</short_description><sys_updated_by>admin</sys_updated_by><upon_reject>Cancel all future Tasks</upon_reject><approval_history/><actual_travel_start/><has_follow_on>false</has_follow_on><dispatched_on/><calendar_duration/><work_notes/><approval>Not Yet Requested</approval><sys_id>78afee7f0fe7ca009b6fc5bce1050e70</sys_id><sys_created_by>admin</sys_created_by><assigned_to/><cmdb_ci/><opened_by><display_value>System Administrator</display_value><link>https://<service-now instance>/api/now/table/sys_user/6816f79cc0a8016401c5a33be04be441</link></opened_by><sys_class_name>Work Order Task</sys_class_name><estimated_travel_duration/><watch_list/><escalation>Normal</escalation><contact_type>Phone</contact_type><time_worked/><comments/></result></response>




Does the WO have to be in a certain state before I can add a child WOT ? What else can I try?




You can always try writing the sys_id directly since you have that information as well.



That being said, always double check triple check ACLs... Although I assume you don't have any issues creating work order tasks from GUI.


URI


https://<service-now instance>/api/now/table/wm_task?sysparm_input_display_value=true


HTTP Action


POST


JSON Request


{


  "parent": [


      {


          "sys_id": "4ffbee7f0fe7ca009b6fc5bce1050e6c"


      }


  ],


  "short_description": "wm task insert test"


}


If I try the above it doesn't work. How else can I pass the parent work order sys_id in the POST ?



Yes, I can create work order tasks from the GUI.