How to query in XPath?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2017 04:43 AM
I am trying out the Automated Test Framework and trying to create our REST API. So I want to check the JSON that is returned. We have created 2 transform maps, so how do I check the 'status' where 'transform_map' is equal to 'Update X'?
When I do '/result/result/status', I get 'skipped, inserted', so how do I filter out only the second part?
This is the JSON that is returned:
{
"import_set": "ISETXXXXXXX",
"staging_table": "u_table",
"result": [
{
"transform_map": "Update X",
"table": "incident",
"display_name": "number",
"display_value": "INCXXXXXXX",
"record_link": "https://instance.service-now.com/api/now/table/incident/SYSID",
"status": "skipped",
"sys_id": "SYSID",
"status_message": "Unable to resolve target record, coalesce values not present: [Script]",
"error_message": "Unable to resolve target record, coalesce values not present: [Script]"
},
{
"transform_map": "Update Y",
"table": "incident",
"display_name": "number",
"display_value": "INCXXXXXXX",
"record_link": "https://instance.service-now.com/api/now/table/incident/SYSID",
"status": "inserted",
"sys_id": "SYSID"
}
]
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2017 04:15 PM
Hi there
Your JSON String is too big, so showing an example with a sample String. Let me know! Please mark as correct if that solves your problem.
var jsonResp = '{role:[{"id": "123", "name": "IT_Role", "owner": "Michael", "desc": "TestRole"}, {"id": "456", "name": "BUSINESS_Role", "owner": "John", "desc": "NewRole2"}]}';
var responseJONObject = new global.JSON().decode(jsonResp);
var roleObject = responseJONObject.role;
for (var x in roleObject) {
if (roleObject[x].id == '123') {
gs.log(roleObject[x].id);
gs.log(roleObject[x].owner);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2017 04:16 PM
Please run above sample code using Scripts - Background to test it out!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2017 01:54 AM
I don't think you understood my question.
I am asking about the 'Assert JSON Response Payload Element' test (https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/administer/auto-test-framework/r... ).
This is what I have now and it works, but I want to only specify the status for only one of the array elements, not both.