Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need help with transform map script

dvelloriy
Kilo Sage

Hi Team,

I am doing transformation of data for one of our monitoring tools which is creating incidents in servicenow.

I need to use data stored in staging table to calculate Configuration item and assignment group of Incident.

 

We have field called "Tags" in staging table which has below data:

 

Hostname:NAP01-OND02,Vitality:V0,Support Team:Real Time Applications,Application Name:EDS

 

So Configuration item on Incident should be NAP01-OND02. If this does not exist in CMDB then it should be "CI NOT Present".

Assignment group = Real Time Applications. If assignment group is not found in group table, then populate with CI.support group.

 

How shall i parse this value and write glide query to populate CI and AG on incident record by creating respective field maps.

 

Appreciate your support.

7 REPLIES 7

Hello Runjay

The script is not working as expected. Its not setting the CI not found when match is not found in CMDB..there is some issue.

Hi @dvelloriy ,

 

I hope you have one ci record with name "CI Not Found" if not then you have to create that.

 

 

"CI Not Found" is present. I think the issue is in the logic somewhere. 

I guess since config item and assignment group are reference fields, we might need to apply a different logic to set the extracted values of ci and suppG.

 

Here is the script i am using which is not working. Do you see any issues here?

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

var str = source.tags;
var ci = '';
var suppG = '';
var arr = str.split(',');
for (i = 0; i < arr.length; i++) {
    if (arr[i].indexOf('Hostname:') == 0) {
        ci = arr[i].split(':')[1];
    }
    if (arr[i].indexOf('Product Team') == 0) {
        suppG = arr[i].split(':')[1];
    }
}


var ciGr = new GlideRecord('cmdb_ci');
    ciGr.addQuery('name', ci);
    ciGr.addQuery('class','CONTAINS','server');
    ciGr.query();
    if (!ciGr.next())
     ci = 'CI Not Found - Hardware';
   

var grpGR = new GlideRecord('sys_user_group');
    grpGR.addQuery('name', suppG);
    grpGR.query();
    if (!grpGR.next()){

    var cmdbGr = new GlideRecord('cmdb_ci');
        cmdbGr.addQuery('name', ci);
        cmdbGr.query();
        if (cmdbGr.next())
        suppG = cmdbGr.support_group;
    }

target.cmdb_ci = ci;
target.assignment_group = suppG;
target.u_resolution_ci = ci;

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