- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 01:46 PM
Trying a outbound integration between two instance .
Goal: If i create an incident in Source , it should create in Target instance as well using Rest message and Business Rule
Under Restmessage create a HTTP Post method :
Business Rule:
When Im testing the HTTP post method , if i hard coded the values able to create the incident with code 201.
But if im dynamically want to give the values using $Caller_ID , it not creating the incident
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2025 02:53 PM
Use ${variable_name} in the content to substitute variables. Also, instead of wrapping these substitutions in double quotes in the content, use JSON.stringify in the business rule to escape any quotation marks in your input values and to automatically wrap the string in double quotes. If you don't do this, and a user includes a double quotes in their input, your JSON will not be properly formatted and will not parse.
The content would look like this:
{
"caller_id":${caller_id},
"short_description":${short_description},
"priority":${Priority},
"state":${State},
"urgency":${urgency}
}
The section of the business rule script that populates the REST message would look like this:
request.setStringParameterNoEscape('caller_id', JSON.stringify(current.caller_id));
request.setStringParameterNoEscape('short_description', JSON.stringify(current.short_description);
request.setStringParameterNoEscape('Priority', JSON.stringify(current.priority));
request.setStringParameterNoEscape('State', JSON.stringify(current.state));
request.setStringParameterNoEscape('urgency', JSON.stringify(current.urgency));
Hope that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2025 12:29 AM
your variable substitutions in Content body field should be like this, so do the same for others
"${caller_id}"
you missed the starting and closing curly brackets
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2025 04:11 AM
Problem Name: Incorrect Variable Substitution in JSON
General Solution:
Use the ${variable} syntax in the JSON body and add the Content-Type header to ensure the payload is parsed correctly by the ServiceNow API.
Detailed Step-by-Step Solution:
Navigate to System Web Services > Outbound > REST Message, open the outbound_demo record, and select the incident_Post HTTP method.
In the HTTP Headers tab, add:
Name: Content-Type
Value: application/json;charset=UTF-8
In the Content section, paste the following JSON with ${} placeholders:
{ "caller_id": "${caller_id}", "short_description": "${short_description}", "priority": "${priority}", "state": "${state}", "urgency": "${urgency}" }
Verify authentication in the Authentication tab (Basic Auth or OAuth) is configured for the target instance.
Create a Business Rule:
Table: Incident [incident]
When: After Insert, Asynchronous
Advanced
Script:
// After insert -> send to remote instance (function executeRule(current) { var rm = new sn_ws.RESTMessageV2('outbound_demo','incident_Post'); var response = rm.execute(); var code = response.getStatusCode(); var body = response.getBody(); if (code !== 201) { gs.error('Integration error: ' + code + ' ' + body); } })(current);
Save and test by creating a new incident, then check logs and verify the incident appears in the target instance.
Alternative:
Use Flow Designer with a REST Action for a no-code integration.
Example Use Case:
Integration Developers can use RESTMessageV2 in an After Insert Business Rule to sync new incidents between instances, leveraging ${variable} placeholders in the JSON body. 😊
Sources:
Rest API Error "{"error":{"message":...}}" – ServiceNow Community (https://www.servicenow.com/community/developer-forum/rest-api-error-quot-quot-error-quot-quot-messag...), explanation of ${variable} syntax requirement.
RESTMessageV2 API reference – ServiceNow Documentation (https://www.servicenow.com/docs/bundle/washingtondc-api-reference/page/app-store/dev_portal/API_refe...), details on execute(), getBody(), and header configuration.
Please mark as the correct answer 😊
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2025 02:53 PM
Use ${variable_name} in the content to substitute variables. Also, instead of wrapping these substitutions in double quotes in the content, use JSON.stringify in the business rule to escape any quotation marks in your input values and to automatically wrap the string in double quotes. If you don't do this, and a user includes a double quotes in their input, your JSON will not be properly formatted and will not parse.
The content would look like this:
{
"caller_id":${caller_id},
"short_description":${short_description},
"priority":${Priority},
"state":${State},
"urgency":${urgency}
}
The section of the business rule script that populates the REST message would look like this:
request.setStringParameterNoEscape('caller_id', JSON.stringify(current.caller_id));
request.setStringParameterNoEscape('short_description', JSON.stringify(current.short_description);
request.setStringParameterNoEscape('Priority', JSON.stringify(current.priority));
request.setStringParameterNoEscape('State', JSON.stringify(current.state));
request.setStringParameterNoEscape('urgency', JSON.stringify(current.urgency));
Hope that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2025 12:29 AM
your variable substitutions in Content body field should be like this, so do the same for others
"${caller_id}"
you missed the starting and closing curly brackets
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2025 04:11 AM
Problem Name: Incorrect Variable Substitution in JSON
General Solution:
Use the ${variable} syntax in the JSON body and add the Content-Type header to ensure the payload is parsed correctly by the ServiceNow API.
Detailed Step-by-Step Solution:
Navigate to System Web Services > Outbound > REST Message, open the outbound_demo record, and select the incident_Post HTTP method.
In the HTTP Headers tab, add:
Name: Content-Type
Value: application/json;charset=UTF-8
In the Content section, paste the following JSON with ${} placeholders:
{ "caller_id": "${caller_id}", "short_description": "${short_description}", "priority": "${priority}", "state": "${state}", "urgency": "${urgency}" }
Verify authentication in the Authentication tab (Basic Auth or OAuth) is configured for the target instance.
Create a Business Rule:
Table: Incident [incident]
When: After Insert, Asynchronous
Advanced
Script:
// After insert -> send to remote instance (function executeRule(current) { var rm = new sn_ws.RESTMessageV2('outbound_demo','incident_Post'); var response = rm.execute(); var code = response.getStatusCode(); var body = response.getBody(); if (code !== 201) { gs.error('Integration error: ' + code + ' ' + body); } })(current);
Save and test by creating a new incident, then check logs and verify the incident appears in the target instance.
Alternative:
Use Flow Designer with a REST Action for a no-code integration.
Example Use Case:
Integration Developers can use RESTMessageV2 in an After Insert Business Rule to sync new incidents between instances, leveraging ${variable} placeholders in the JSON body. 😊
Sources:
Rest API Error "{"error":{"message":...}}" – ServiceNow Community (https://www.servicenow.com/community/developer-forum/rest-api-error-quot-quot-error-quot-quot-messag...), explanation of ${variable} syntax requirement.
RESTMessageV2 API reference – ServiceNow Documentation (https://www.servicenow.com/docs/bundle/washingtondc-api-reference/page/app-store/dev_portal/API_refe...), details on execute(), getBody(), and header configuration.
Please mark as the correct answer 😊