The CreatorCon Call for Content is officially open! Get started here.

How to query in XPath?

peterraeves
Mega Guru

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"
  }
  ]
}

3 REPLIES 3

Sashi K1
Kilo Guru

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);


}


}


Please run above sample code using Scripts - Background to test it out!


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.


Image 5.png