Transform script to load relationship between same parent and child name with different classes

Jyoti88
Tera Contributor

Once create  business application using transform map, in relationship how we can import parent child relationship with same name for both parent and child with different classes

Parent :ABC

parent class: business application

Child: ABC

child class: application service

type: Consumes:: Consumed by

 

can anyone please provide the code to achieve it?

Jyoti88_0-1702901333184.png

Parent class should be Business Application.

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Jyoti88 

 

To do this You need 3 transform map

 

1. To get the Business Application

2. To get the Application Service

3. To get the relationship

for 3rd one, download the excel template from cmdb_rel_ci table

ask user to update the data

Load data via import set table

Create Transform map

Run.

 

Process is same but make sure the both Services must exits in CSDM.

*************************************************************************************************************
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]

****************************************************************************************************************

Hello @Dr Atul G- LNG ,

 

We already load business applications and application services , now we have to load relationship between both, but classes are chosen incorrectly , because of duplicate names, but there classes are different.

We want classes should be selected properly for both parent and child.

 

Regrds,

Jyoti

Hi @Jyoti88 

 

Where these classes picked up wrongly?

 

(but classes are chosen incorrectly , because of duplicate names, but there classes are different.)

*************************************************************************************************************
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]

****************************************************************************************************************

SunilKumar_P
Giga Sage

Hi @Jyoti88, You need to have the OnComplete transform script. Can you try the below script?

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
 
//Get the sys_id of Business Application.
    var busApp = source.u_business_application;
    var busAppId = '';
    var grBA = new GlideRecord("cmdb_ci_business_app");
    grBA.addQuery("name", busApp);
    grBA.query();
    if (grBA.next()) {
        busAppId = grBA.sys_id;
    }
//Get the sys_id of Application Service.
    var appSer = source.u_application_service;
    var appSerId = '';
    var grApp = new GlideRecord("cmdb_ci_service");
    grApp.addQuery("name", appSer);
    grApp.query();
    if (grApp.next()) {
        appSerId = grApp.sys_id;
    }
 
//Create a relationship.
    var grCiRel = new GlideRecord("cmdb_rel_ci");
    grCiRel.initialize();
    grCiRel.parent = busAppId;
    grCiRel.child = appSerId;
    grCiRel.type = "41008aa6ef32010098d5925495c0fb94" //Consumes::Consumed by
    grCiRel.insert();

})(source, map, log, target);

 

Regards,

Sunil