Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Transform map - How to create incident but will not populate reference field based on condition

ceraulo
Mega Guru

Hello!

I have a transform map that creates an incident record on transform. The source table has a field called config_item and populated the cmdb_ci field on the target table.

 

I want to create the incident but leave the cmdb_ci field blank if the condition does not meet the condition. The condition is 'sys_class_name=cmdb_ci_server^ORsys_class_name=cmdb_ci_win_server^operational_status=1'.

 

Is this possible?

Please help!

 

Thank you.

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@ceraulo 

then you should use field map script and handle it

Also ensure you set name in Referenced value field name

Also choice action as ignore

 

AnkurBawiskar_0-1703833020512.png

 

answer = (function transformEntry(source) {

	// Add your code here
	var incomingValue = source.u_config_item; // use the source field name here
	var gr = new GlideRecord("cmdb_ci");
	gr.addQuery("name", incomingValue); // query with name if incoming value is CI name
	gr.addEncodedQuery('sys_class_name=cmdb_ci_server^ORsys_class_name=cmdb_ci_win_server^operational_status=1');
	gr.query();
	if (gr.next()) {
		return gr.name;
	}
	else{
		return -1; // don't allow update
	}

})(source);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Siddhesh Gawade
Mega Sage

Hello @ceraulo ,

 

You can do this by using a Onbefore transform script as below: 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Get the sys_class_name and operational_status from the source record
var sysClassName = source.u_config_item.sys_class_name.toString();
var operationalStatus = source.u_config_item.operational_status.toString();

// Check the condition
if ((sysClassName == 'cmdb_ci_server' || sysClassName == 'cmdb_ci_win_server') && operationalStatus == '1') {
// If condition is met, copy the config_item to the target record
target.cmdb_ci = source.u_config_item;
} else {
// If condition is not met, leave the cmdb_ci field blank
target.cmdb_ci = '';
}
})(source, map, log, target);

 

Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.


Regards,

Siddhesh