- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2024 07:26 AM
Dear Experts.
I need a quick help struck with a code. I am trying to run a onAfter transform scrip to create relationship and also once created the next run of the transform map should not create new one (if a relationship has already been inserted) - I am able to create the relationship which is working as expected but somehow the conditions that will prevent relationship is not getting created.
What I am thinking is if Application Name.sys_id OR Business_App.sys_Id or TYPE is present, it should not create a new one. Can someone help ?
(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.initialize();
cmdbRelGR.parent = target.sys_id;
cmdbRelGR.child = businessAppSysID;
cmdbRelGR.type = "Consumes::Consumed by";
cmdbRelGR.insert();
}
else {
ignore = true;
}
})(source, map, log, target);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2024 02:46 PM
Try below:
(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('parent', target.sys_id);
cmdbRelGR.addQuery('child', businessAppSysID);
cmdbRelGR.addQuery('type', '41008aa6ef32010098d5925495c0fb94'); //Sys ID of "Consumes::Consumed by"
cmdbRelGR.query();
if (cmdbRelGR.next())
//do nothing
else {
cmdbRelGR.initialize();
cmdbRelGR.parent = target.sys_id;
cmdbRelGR.child = businessAppSysID;
cmdbRelGR.type = '41008aa6ef32010098d5925495c0fb94';
cmdbRelGR.insert();
}
}
})(source, map, log, target);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2024 02:46 PM
Try below:
(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('parent', target.sys_id);
cmdbRelGR.addQuery('child', businessAppSysID);
cmdbRelGR.addQuery('type', '41008aa6ef32010098d5925495c0fb94'); //Sys ID of "Consumes::Consumed by"
cmdbRelGR.query();
if (cmdbRelGR.next())
//do nothing
else {
cmdbRelGR.initialize();
cmdbRelGR.parent = target.sys_id;
cmdbRelGR.child = businessAppSysID;
cmdbRelGR.type = '41008aa6ef32010098d5925495c0fb94';
cmdbRelGR.insert();
}
}
})(source, map, log, target);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2024 10:06 AM
Thank you Maroon Byte.. I was able to edit the code. However I wanted to make the business application as the Parent and application service as a child. I am unable to switch that ! Any advise
(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);
I
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2024 11:10 AM - edited ‎04-09-2024 11:17 AM
type needs to be the sys_id of "Consumes::Consumed by", otherwise, insert will work but type will be empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2024 01:39 PM - edited ‎04-09-2024 01:40 PM
are you able to advise on how we can make the reverse the parent and the child.
Business App as Parent
App Service as Child
Whenever I am reversing the it, it is working but I am also taking the App Service as Parent and Business App as child.