Unable to Reverse the Parent Child Relationship
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 09:44 PM
Dear Experts,
I have a transform map targetting the Application service & a OnAfter script which will map the Application and Business application togather. The script is working fine in creating the relationship, however instead of app service to become a parent, I need Business App to be the parent and child will be app service. Here is the code. Can someone suggest ?
[19:02] Bose, Nilanjan
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var appRel = target.u_application_release_cit_id;
var businessAppSysID;
var getBusinessApplication = new GlideRecord("cmdb_ci_business_app");
getBusinessApplication.addEncodedQuery("correlation_id=" + appRel);
getBusinessApplication.query();
if (getBusinessApplication.next()) {
businessAppSysID = getBusinessApplication.sys_id;
var cmdbRelGR = new GlideRecord("cmdb_rel_ci");
//cmdbRelGR.addEncodedQuery('parent=' + target.sys_id + '^child=' + businessAppSysID);
cmdbRelGR.addEncodedQuery('parent=' + businessAppSysID + '^child=' + target.sys_id);
cmdbRelGR.query();
if (!cmdbRelGR.next()) {
cmdbRelGR.initialize();
// cmdbRelGR.parent = target.sys_id;
// cmdbRelGR.child = businessAppSysID;
cmdbRelGR.parent = businessAppSysID;
cmdbRelGR.child = target.sys_id;
cmdbRelGR.type = "Consumes::Consumed by";
cmdbRelGR.insert();
}
} else {
ignore = true;
}
})(source, map, log, target);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 04:43 AM
@Nilanjan1
ensure your debug logs (gs.log or gs.info) are sufficiently detailing the process for each record being processed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 05:46 AM
Hi @Nilanjan1 ,
I trust you are doing great.
Please find the updated code for the same.
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var appRel = target.u_application_release_cit_id;
var businessAppSysID;
var getBusinessApplication = new GlideRecord("cmdb_ci_business_app");
getBusinessApplication.addEncodedQuery("correlation_id=" + appRel);
getBusinessApplication.query();
if (getBusinessApplication.next()) {
businessAppSysID = getBusinessApplication.sys_id;
var cmdbRelGR = new GlideRecord("cmdb_rel_ci");
// Switching parent and child assignments
cmdbRelGR.addEncodedQuery('parent=' + target.sys_id + '^child=' + businessAppSysID);
cmdbRelGR.query();
if (!cmdbRelGR.next()) {
cmdbRelGR.initialize();
// Switching parent and child assignments
cmdbRelGR.parent = businessAppSysID;
cmdbRelGR.child = target.sys_id;
cmdbRelGR.type = "Consumes::Consumed by";
cmdbRelGR.insert();
}
} else {
ignore = true;
}
})(source, map, log, target);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2024 07:44 AM - edited 04-15-2024 09:12 AM
Thank you so much Amit, I did use the same script but it failed somehow! If there is a requirement where if there is a change in the relationship from one business application to another application service, I need to drop the previous relationship which was defined in the previous time.
(function runTransformScript(source, map, log, target /* undefined onStart */ ) {
var appRel = target.u_application_release_cit_id;
var businessAppSysID;
var getBusinessApplication = new GlideRecord("cmdb_ci_business_app");
getBusinessApplication.addEncodedQuery("correlation_id=" + appRel);
getBusinessApplication.query();
if (getBusinessApplication.next()) {
businessAppSysID = getBusinessApplication.sys_id;
var cmdbRelGR = new GlideRecord("cmdb_rel_ci");
cmdbRelGR.addQuery('child', target.sys_id);
cmdbRelGR.addQuery('parent', businessAppSysID);
cmdbRelGR.addQuery('type', '41008aa6ef32010098d5925495c0fb94'); //Sys ID of "Consumes::Consumed by"
cmdbRelGR.query();
if (!cmdbRelGR.next()) {
cmdbRelGR.initialize();
cmdbRelGR.parent = businessAppSysID;
cmdbRelGR.child = target.sys_id;
cmdbRelGR.type = gs.getProperty('Consumes::Consumed by');
cmdbRelGR.insert();
}
}
})(source, map, log, target);