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.

coalesce on multiple fields not working transform script

arey yaar
Giga Guru

I have mentioned coalesce in two fields and it isn't consider either one in each condition

find_real_file.png

Below i have mentioned the script

Where the insert takes duplicate values.. 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
	var gr=new GlideRecord('cmdb_ci_appl');
	gr.query();
	while(gr.next())
		{


		
if( action=='update' && source.u_number == gr.u_number && source.u_name==gr.name && JSUtil.notNil(source.u_number))  

//If application id and application name is same then data should update
  {
	ignore=false;
   }
	
//If application id is empty and application name is present then it should insert
			
if( action=='insert' && source.u_number== "" && source.u_name!= gr.name)
{
//if application Id is empty  and application name is already present then it should skip
	ignore=false;
}
		}
	


})(source, map, log, target);
1 ACCEPTED SOLUTION

Vaiju
Giga Contributor

Hello Subhanand,

 

'Coalesce' field is used to create unique record in table.

If you make coalesce true for both fields, then it will take field1 && field2 to create unique record.

 

In your case it will consider unique values of 'name' and 'u_number' to create record.

So that modify your script accordingly.

 

 

Thanks & regards,

Vaijanath Shintre

 

View solution in original post

2 REPLIES 2

Vaiju
Giga Contributor

Hello Subhanand,

 

'Coalesce' field is used to create unique record in table.

If you make coalesce true for both fields, then it will take field1 && field2 to create unique record.

 

In your case it will consider unique values of 'name' and 'u_number' to create record.

So that modify your script accordingly.

 

 

Thanks & regards,

Vaijanath Shintre

 

then how can i solve these issues 

//If application id and application name is same then data should update

//If application id is empty and application name is present then it should insert

//if application Id is empty and application name is already present then it should skip

 

Becoz i need both of them to check for existing fields ,if there are any duplicates it inserts even i used coalesce and the script to check the condition

It didnt work can i know y?