Integration between 2 instances
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
HI Community,
I have a requirement where in dev instances i have created a catalog item and once the request is raised in dev instances then a sla record need to be created in sandbox instances...based on variables (like name, type, target etc) in catalog item then the record need to be created in sla def table
For this i have setup the integration between dev and sandbox.
created rest message in dev and written a script in BR.
Record is getting created but it is empty not sure what is that i'm missing
rest message: just for testing i have used only some variables
After insert BR:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @suuriyas
Based on your screenshots and script, the problem is most likely that you are not setting the target variable in your Business Rule.
Your REST Message's Content field (from the first image) defines a JSON payload that requires four values:
-
name -
type -
target -
start_condition
Your Business Rule script successfully gets the values for name, type, and start_condition, but it never retrieves or sets the target variable. The target instance is likely receiving a JSON payload with a null value for target, causing it to create an empty or incomplete record.
Update this BR:
(function executeRule(current, previous /*null when async*/) {
try {
gs.sleep(2000); // Note: A sleep here is unusual, but I'll leave it as it was in your script.
var vars = {};
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('request_item', current.sys_id);
gr.query();
while (gr.next()) {
var opt = new GlideRecord('sc_item_option');
if (opt.get(gr.sc_item_option)) {
vars[opt.item_option_new.name.toString()] = opt.value.toString();
}
}
// Get all your variable values
var slaName = vars['name'];
var slaType = vars['type'];
var slaTarget = vars['target']; // <-- **1. ADDED THIS LINE**
var startCondition = vars['start_condition'];
gs.info('creating sla in target instances with values' + 'Name=' + slaName);
var r = new sn_ws.RESTMessageV2('SLA Creation', 'Post');
// Set ALL required parameters
r.setStringParameter('name', slaName);
r.setStringParameter('type', slaType);
r.setStringParameter('target', slaTarget); // <-- **2. ADDED THIS LINE**
r.setStringParameter('start_condition', startCondition);
gs.info('debug: sla payload values name' + slaName);
// This log is your most important debugging tool
gs.info('Debug : request body' + r.getRequestBody());
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info('SLA Creation response status: ' + httpStatus);
gs.info('SLA Creation response body: ' + responseBody);
} catch (ex) {
var message = ex.message;
gs.error('SLA Creation BR Error: ' + message); // It's good practice to log errors
}
})(current, previous);
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
50m ago
Thanks for replying
I tried your script by adding target but still it create empty record
this is what i see in logs
In catalog item i have created all the variables similar to the sla def table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @suuriyas
My video will give you a better idea — even though it’s an interaction between ServiceNow and ServiceNow (SN–SN).
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
