Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need help on passing key value pairs in Rest Post method

divyalakshmi
Tera Guru

Hi,

I have a requirement where whenever a record is created in a particular table (eg incident), i should pass the ticket number and other fields in key value pair like below in rest.

{

  "incidentid": "INC00101",

  "properties": [

      {

          "code": "summary",

          "value": "test incident"

      },

{

"code":"description",

"value":"test desc"

},      

  ]

}

I have configured the Rest Outbound and the outbound requires only two parameters "incidentid" and "properties".

here Properties should push all the filled field names and values. i have written a BR on this table to call the rest outbound and trying to pass summary and application name in key value pair

var property=[];

var json = new JSON();

var r = new sn_ws.RESTMessageV2(incidentRestMessage, 'post');

r.setStringParameter('incidentid', current.number);

//summary

if(current.short_description)

{

var summary={"code":"Summary","value":current.short_description.toString()};

property.push(summary);

}

//ApplicationCode

if(current.cmdb_ci)

{

var ci={"code":"ApplicationCode","value":current.cmdb_ci.getDisplayValue().toString()};

property.push(ci);

}

r.setStringParameter('properties',JSON.stringify(property));

var response = r.execute();

var responseBody = response.getBody();

var rBody = r.getRequestBody();

gs.log("rest call for "+current.number +"   "+rBody); If i try to log the request body to check if the input parameters are correct i get the below log

rest call for INC00101{"incidentid": "INC00101","properties":"[{"code":"Summary","value":"heloo"},{"code":"ApplicationCode","value":"Fire TOOL"}]"}.

i am not sure why this " comes in place of " ". can anyone help me on achieving this ?

Thanks,

Divya Lakshmi.

1 ACCEPTED SOLUTION

Gaurav Bajaj
Mega Sage

Hi Divya,



Did you try setting parameter with


setStringParameterNoEscape('properties',JSON.stringify(property));



Thanks


Gaurav


View solution in original post

5 REPLIES 5

Hi,



Replied to your new post as this one has been already answered.



Thanks


Gaurav