Integration between 2 instances
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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
3 weeks ago
@suuriyas whats the issue now? is it working
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
3 weeks ago
HI @Deepak Shaerma ,
I have fixed the script it is working sla record is getting created with details expect for one field duration....in sla form duration field will get displayed when duration type is user specified (no backend name) struck with this part duration field not populating
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @suuriyas
Could you please try this script:
(function executeRule(current, previous /*null when async*/ ) {
var mvrs = JSON.parse(current.variables.sla_configuration);
var i = 0;
while (i < mvrs.length) {
var name = mvrs[i].name + '';
var type = mvrs[i].type + '';
var target = mvrs[i].target + '';
var table = mvrs[i].collection + '';
var flow = mvrs[i].flow + '';
var vendor = mvrs[i].vendor + '';
var service = mvrs[i].service_commitment + '';
var timezonesource = mvrs[i].timezone_source + '';
var logging = mvrs[i].enable_logging + '';
var active = mvrs[i].active + '';
var durationtype = mvrs[i].duration_type + '';
var relativeduration = mvrs[i].relative_duration_works_on + '';
var duration = mvrs[i].duration + '';
var schedulesource = mvrs[i].schedule_source + '';
var schedulesourcefield = mvrs[i].schedule_source_field + '';
var schedule = mvrs[i].schedule + '';
var timezone = mvrs[i].timezone + '';
var startcondition = mvrs[i].start_condition + '';
var retroactive = mvrs[i].retroactive + '';
var retroactivepause = mvrs[i].retroactive_pause + '';
var startto = mvrs[i].set_start_to + '';
var whentocancel = mvrs[i].when_to_cancel + '';
var cancelcondition = mvrs[i].cancel_condition + '';
var pausecondition = mvrs[i].pause_condition + '';
var toresume = mvrs[i].when_to_resume + '';
var resumecondition = mvrs[i].resume_condition + '';
var stopcondition = mvrs[i].stop_condition + '';
var resetcondition = mvrs[i].reset_condition + '';
var resetaction = mvrs[i].reset_action + '';
var tablename = '';
if (table) {
var tbl = new GlideRecord('sys_db_object');
if (tbl.get(table)) {
tablename = tbl.name.toString();
}
}
// --- FIX STARTS HERE ---
var glideDur = '';
if (duration) {
// 1. Convert string to integer
// 2. Multiply by 1000 to get milliseconds (Assumes input is Seconds)
// 3. Create GlideDuration object
// 4. Get the internal string format (1970-01-01 HH:mm:ss)
var gd = new GlideDuration(parseInt(duration, 10) * 1000);
glideDur = gd.getValue();
}
// --- FIX ENDS HERE ---
try {
var r = new sn_ws.RESTMessageV2('SLA Creation', 'Post');
r.setStringParameter('name', name);
r.setStringParameter('type', type);
r.setStringParameter('target', target);
r.setStringParameter('collection', tablename);
r.setStringParameter('flow', flow);
r.setStringParameter('vendor', vendor);
r.setStringParameter('timezone_source', timezonesource);
r.setStringParameterNoEscape('reset_condition', resetcondition);
r.setStringParameterNoEscape('timezone', timezone);
// Send the formatted duration string
r.setStringParameterNoEscape('duration', glideDur);
r.setStringParameterNoEscape('active', active);
r.setStringParameterNoEscape('enable_logging', logging);
r.setStringParameterNoEscape('start_condition', startcondition);
r.setStringParameterNoEscape('schedule', schedule);
r.setStringParameterNoEscape('stop_condition', stopcondition);
r.setStringParameterNoEscape('schedule_source', schedulesource);
r.setStringParameterNoEscape('set_start_to', startto);
r.setStringParameterNoEscape('resume_condition', resumecondition);
r.setStringParameterNoEscape('pause_condition', pausecondition);
r.setStringParameterNoEscape('duration_type', durationtype);
r.setStringParameterNoEscape('retroactive_pause', retroactivepause);
r.setStringParameterNoEscape('cancel_condition', cancelcondition);
r.setStringParameterNoEscape('service_commitment', service);
r.setStringParameterNoEscape('when_to_resume', toresume);
r.setStringParameterNoEscape('reset_action', resetaction);
r.setStringParameterNoEscape('when_to_cancel', whentocancel);
r.setStringParameterNoEscape('relative_duration_works_on', relativeduration);
r.setStringParameterNoEscape('schedule_source_field', schedulesourcefield);
r.setStringParameterNoEscape('retroactive', retroactive);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info('DEBUG response for row' + (i + 1) + '>' + httpStatus + ' > ' + responseBody);
} catch (ex) {
var message = ex.message;
gs.error('DEBUG SLA Creation BR Error: ' + message);
}
i++;
}
})(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
Tuesday - last edited Tuesday
no it did not works
It throws an error
DEBUG SLA Creation BR Error: Cannot convert NaN to java.lang.Long (sys_script line 56)
that is
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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]
****************************************************************************************************************
