Unable to get the Fix Script Running to create a relationship

Nilanjan1
Mega Sage

Hello Experts. 

I am trying to run a fix script which will help to create a type consumes::consumedby, however when I am trying to compare two fields for e.g. u_application_release_cit_id from the Application service with the correlation_id of a business application should match to create a relationship. However.  it is not returning any value. I am unable to understand where I am going wrong

var getAppSrv = new GlideRecord('cmdb_ci_service_auto');
getAppSrv.addEncodedQuery('u_application_release_in_citISNOTEMPTY');
getAppSrv.orderByDesc('sys_created_on');
//getAppSrv.setLimit(20);
getAppSrv.query();
gs.info(getAppSrv.getRowCount());
while (getAppSrv.next()) {
    var getBussApp = new GlideRecord('cmdb_ci_business_app');
    getBussApp.addEncodedQuery('correlation_id=' + getAppSrv.u_application_release_cit);
    getBussApp.query();
    gs.info(getAppSrv.name+'::'+ getAppSrv.u_application_release_in_cit + getBussApp.getRowCount());
if (getBussApp.next()) {
        var gr = new GlideRecord('cmdb_rel_ci');
        gr.initialize();
        gr.parent = getAppSrv;
        gr.child =  getBussApp;
        gr.type = '41008aa6ef32010098d5925495c0fb94';
        gr.insert();
    }

 

1 REPLY 1

Anurag Tripathi
Mega Patron
Mega Patron

try this

var getAppSrv = new GlideRecord('cmdb_ci_service_auto');
getAppSrv.addEncodedQuery('u_application_release_in_citISNOTEMPTY');
getAppSrv.orderByDesc('sys_created_on');
//getAppSrv.setLimit(20);
getAppSrv.query();
gs.info(getAppSrv.getRowCount());
while (getAppSrv.next()) {
    var getBussApp = new GlideRecord('cmdb_ci_business_app');
    getBussApp.addEncodedQuery('correlation_id=' + getAppSrv.u_application_release_cit);
    getBussApp.query();
    gs.info(getAppSrv.name+'::'+ getAppSrv.u_application_release_in_cit + getBussApp.getRowCount());
if (getBussApp.next()) {
        var gr = new GlideRecord('cmdb_rel_ci');
        gr.initialize();
        gr.parent = getAppSrv.sys_id;
        gr.child =  getBussApp.sys_id;
        gr.type = '41008aa6ef32010098d5925495c0fb94';
        gr.insert();
    }
-Anurag