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.

Issue with Transform map

Ak8977
Tera Expert

Hello all,

I created one transform map. The target table is cmdb_ci table.
I have a requirement that the ci from location "xyz" need to be update else the record need to be ignored.
the location field was not available in source table , it was only available in target table referring to "cmn_location" table. how I can achieve it.
Thanks,

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @Ak8977,

 

You can achieve such logic by implementing a 'Transform Script' of type 'onBefore'. (Navigate to the bottom of the Transform Map form and look at the tabs/related lists to see the 'Transform Scripts'. Create a New Script

 

Essentially you're going to have to look up the matching 'CI' based on the source CI (Hopefully something unique such as Serial Number rather than CI Name).

Here's a sample script you can use and adjust accordingly for your needs:

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

 

 

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

	// sourceLocation is the value used to check and confirm against - your 'xyz' example.
	var sourceLocation = '815 E Street, San Diego,CA';
	//Find match CI and check location. Serial No is a common unique ID for a CI. I recommend not using name as a query parameter. Substitute 'serial_number' with whatever field you're using from the source data to find the match in cmdb_ci
	if (source.serial_number != ''){
		//Lookup location of target CI
		var ciGR = new GlideRecord('cmdb_ci');
		ciGR.addQuery('serial_number', source.serial_number);
		ciGR.addQuery('location.name',sourceLocation);
		ciGR.query();
		if(ciGR.next()){
			//Allow the update - do nothing or implement any other logic here
		}
		else{
			//Skip record
			ignore = true;
		}
	}

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

 

 

View solution in original post

1 REPLY 1

Robbie
Kilo Patron
Kilo Patron

Hi @Ak8977,

 

You can achieve such logic by implementing a 'Transform Script' of type 'onBefore'. (Navigate to the bottom of the Transform Map form and look at the tabs/related lists to see the 'Transform Scripts'. Create a New Script

 

Essentially you're going to have to look up the matching 'CI' based on the source CI (Hopefully something unique such as Serial Number rather than CI Name).

Here's a sample script you can use and adjust accordingly for your needs:

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

 

 

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

	// sourceLocation is the value used to check and confirm against - your 'xyz' example.
	var sourceLocation = '815 E Street, San Diego,CA';
	//Find match CI and check location. Serial No is a common unique ID for a CI. I recommend not using name as a query parameter. Substitute 'serial_number' with whatever field you're using from the source data to find the match in cmdb_ci
	if (source.serial_number != ''){
		//Lookup location of target CI
		var ciGR = new GlideRecord('cmdb_ci');
		ciGR.addQuery('serial_number', source.serial_number);
		ciGR.addQuery('location.name',sourceLocation);
		ciGR.query();
		if(ciGR.next()){
			//Allow the update - do nothing or implement any other logic here
		}
		else{
			//Skip record
			ignore = true;
		}
	}

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