Sending JSON object via outbound REST message

Mahesh111
Tera Contributor

I have to send incident details in the below JSON format to third party tool . I have written the REST message and business rule on incident table to invoke the REST message. Could anyone please help me with the business rule script to send below JSON object

 

TroubleTicketStatusChangeEvent {

id
href
eventId
eventTime
eventType
correlationId
domain
title
description
priority
timeOcurred
event {

id
href
creationDate
description
expectedResolutionDate
externalId
lastUpdate
name
priority
requestedResolutionDate
resolutionDate
severity
statusChangeDate
statusChangeReason
ticketType
attachment
channel {

id
href
name
@baseType
@schemaLocation
@type
@referredType
}

note
relatedEntity
relatedParty
status TroubleTicketStatusType
statusChange
troubleTicketRelationship
@baseType
@schemaLocation
@type

}

}

2 REPLIES 2

Nayan  Dhamane
Kilo Sage
Kilo Sage

Hello @Mahesh111 ,

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

 

Adding links for referrence:
https://www.servicenow.com/community/developer-forum/how-to-easily-build-json-body-to-be-pass-as-a-p...

https://www.servicenow.com/community/developer-forum/rest-api-post-using-json/m-p/2153790

https://john-james-andersen.com/blog/service-now/easy-base64-encoding-in-servicenow.html

 

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

@Nayan Dhamane 

This works from script but how to do it like passing variables to REST outbound Message?