can we make a field coalesce with the use of script in transform maps?

Dhruv Chandan
Giga Guru

For Example in my Transform Map, we have two fields

  • Company Name ( coalesce )
  • Location Name ( coalesce )

and our loadsheet has three fields

  • Company Name
  • Location Name
  • Company ID

I want to device a script so that if the "Company Name" is not present in the load sheet then , we can make source's "Company ID" as coalesce via script in transform map.

Please any help will be appreciated...

Regards,

Dhruv

4 REPLIES 4

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I think you can do that with a scripted transform in the transform map for your company name field. Just write a script that sets the answer variable to the company name, and if that is empty, the company id field.


i tried the below script in the transform map field's option, but it does't seems to work...



answer(function(){


var source_field;



if(source.u_company_id.trim() !=""){


source_field_cmpany = source.u_company_id;


}



else if(source.u_company.trim() !=""){


souce_field_company = source.u_company;


}



return source_field_company;


})();


Your variables didn't match up, try something like this:



answer = (function(){


var source_field_company = '';



if(source.u_company_id.trim() !=""){


source_field_company = source.u_company_id;


}



else if(source.u_company.trim() !=""){


source_field_company = source.u_company;


}



return source_field_company;


})();


tried this also, but it   doesn't seems to work out.



I'm trying to figure out a logic that with some script "coalesce" field can be made dynamic. Even though i wrote this in the field's script and tried to fetch the source fields value in the on before script it doesn't show up. eg:-



we use the above script in the field's script and then in the on before when i check he value of "source_field_company"   then it comes out to be blank. Again the same question , is here a way though which we can device a script so that the coalesce field can be made dynamic.



Regards,


Dhruv Chandan