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

Runjay Patel
Giga Sage

Hi @dvelloriy ,

 

You can use below code to do the mapping in your transform map script.

 

 

var str = source.u_tag;
//'Hostname:NAP01-OND02,Vitality:V0,Support Team:Real Time Applications,Application Name:EDS';

var arr = str.split(',');

var ci = arr[0].split(':')[1];
var suppG = arr[2].split(':')[1];


var incGr = new GlideRecord('incident');
    incGr.addQuery('cmdb_ci', ci);
    incGr.query();
    if (!incGr.next()) 
     ci = 'CI NOT Present';
    

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

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

target.ci = ci;
target.assignment_group = suppG;

 

 

Please Mark Correct if this solves your query and also mark Helpful if you find my response worthy based on the impact.

Thanks Runjay. One query, why are we querying Incident table below? I think we should query cmdb_ci table. Please advise.

var incGr = new GlideRecord('incident');
    incGr.addQuery('cmdb_ci', ci);
    incGr.query();
    if (!incGr.next()) 
     ci = 'CI NOT Present';

 

 

Hi @dvelloriy 

 

Yes you are right instead of incident change cmdb_ci.

 

 

Runjay Patel
Giga Sage

Hi @dvelloriy ,


Let me know if still facing any issue.

 

Please Mark Correct if this solves your query and also mark Helpful if you find my response worthy based on the impact.