Dynamic Coalesce field in the Transform Maps

rahulrockkk
Tera Contributor

Hi Team,

Is there any way to set the "Coalesce" field to true based on the source value in the transform maps? Dynamically setting the "Coalesce" field to true or false based on the value received in the source field. Please provide your support as soon as possible.

 

Regards

Rahul

16 REPLIES 16

@rahulrockkk 

As per my understanding I don't think so.

If you use onBefore transform script you can use any field as coalesce during the query and would give you the flexibility going forward for code maintenance.

Regards
Ankur

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

@Ankur Bawiskar Could you please provide your support to set the coalesce field in the onBefore transform Script.

@rahulrockkk 

Example

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

	// Add your code here

	var incomingValue = source.u_myField;
	var incomingFieldA = source.u_fieldA;
	var incomingFieldB = source.u_fieldB;

	var gr = new GlideRecord('target table');
	if(incomingValue == 'Hello'){
		gr.addQuery("fieldA", incomingFieldA);
	}
	else if(incomingValue == "BYE"){
		gr.addQuery("fieldB", incomingFieldB);
	}
	gr.query();
	if(gr.next()){
		// record found now map and update
		gr.fieldc = source.u_fieldC;
		ignore = true;

	}	

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

Regards
Ankur

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

@rahulrockkk 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

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

Sai Anna
ServiceNow Employee
ServiceNow Employee

Hello,

As per my knowledge, we cannot dynamically change the "Coalesce" value in field maps. to be honest we should not do configuration changes dynamically based on data. I would recommend writing your logic in the Transform scripts or the "Script' field on the Transform map record.

you have to explicitly write the logic for insert and update operations. Import set data can be accessed using "source". at the end of the script have "ignore=true" so duplicates will not be created.