How to easily build Json body to be pass as a POST rest body param

wakespirit
Kilo Guru

Dear all,

I have the following Json body message that I need to pass to a REST POST API in servicenow.

The json is as below :

{
    "status": "sent",
    "emailSubject": "Sent from the DocuSign REST API",
    "documents": [{
        "documentId": "1",
        "name": "mydoc.pdf",
        "documentBase64": "...."   }],
    "recipients": {
        "signers": [{
            "email": "xxx@hotmail.com",
            "name": "xxxx",
            "recipientId": "1",
            "routingOrder": "1"
        }],
  "carbonCopies": [{
                "email": "<instance>@service-now.com",
                "name": "SN",
                "recipientId": "2",
                "routingOrder": "2"
            }]
    }
}

How to get all the element has variables object in order to inject dynamic content and then build from the object the Json body ?

Thanks for help

regards

 

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

you need to pass the JSON column name as string and then define the value like below sample script. 

 

Sample example:

 

var r = new sn_ws.RESTMessageV2('test', 'Create Record');

var body =
'{ "fields":{ "customfield_14798":{ "value":"'+current.buService+'" }, "description":"'+current.desc+'", "customfield_14797":"'+current.clean_text+'", "customfield_15073":"'+current.number+'", "issuetype":{ "name":"'+current.temp+'" }, "duedate":"'+current.dd+'", "summary":"'+current.title+'", "reporter":{ "name":"'+current.value+'" }, "project":{ "key":"RM" } }}';

 

r.setRequestBody(body);

View solution in original post

3 REPLIES 3

Harsh Vardhan
Giga Patron

you need to pass the JSON column name as string and then define the value like below sample script. 

 

Sample example:

 

var r = new sn_ws.RESTMessageV2('test', 'Create Record');

var body =
'{ "fields":{ "customfield_14798":{ "value":"'+current.buService+'" }, "description":"'+current.desc+'", "customfield_14797":"'+current.clean_text+'", "customfield_15073":"'+current.number+'", "issuetype":{ "name":"'+current.temp+'" }, "duedate":"'+current.dd+'", "summary":"'+current.title+'", "reporter":{ "name":"'+current.value+'" }, "project":{ "key":"RM" } }}';

 

r.setRequestBody(body);

Thanks for your reply, will try

As you can see in my post body I need to pass a document base 64 info.

How to convert a file in documentBase64 format in serviceNow script ?