Transform script to check the source record exist in target table

Sangeetha8
Tera Contributor

Hi All,

 

I had a requirement to check the source field(caller)incident table is exist in the target field(approver)user table (sys_user) if the record is exist then map that field,else keep the target field as empty 

 

How to achieve this using tranform script in field mapping

 

Thanks

8 REPLIES 8

PrashantLearnIT
Giga Sage

Hi @Sangeetha8 

 

You can make the field mapping coalesce as true, it will work same way how you have to do.

 

For More Details Refer this link - https://docs.servicenow.com/bundle/vancouver-integrate-applications/page/administer/import-sets/conc...

 

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Sangeetha8 

 

You can use coalsec but I am interested to know what is exact use case. 

https://youtu.be/6dU9yBQPq_I

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************
ServiceNow #TechnoFuncational Disclaimer: These videos are from my training batch. These videos did not promote any ServiceNow Sales pitch or marketing. These videos are only for knowledge purposes & basic on my experience & Knowledge. Redistribution or copying of functionality is not allowed! ...

Hi @Dr Atul G- LNG 

My issue is that once integration is happened there is a empty record gets created in the sys_user table if there is no matching found in field mapping.

 

How to rectify this issue

Can I write a source script?

Hi @Sangeetha8,

 

This is very easily skipped by the use of an 'onBefore' 'Transform Script'.

See the below screenshot to help visualize and use the following code within the Source Script. (Obviously, check against the appropriate field for your needs. Here I am using the email address)

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
 
if(source.u_email == target.email || source.u_email == target.user_name){
ignore = true;
}
 
})(source, map, log, target);

 

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

 

Screenshot 2024-01-30 at 09.34.07.png

Screenshot 2024-01-30 at 09.33.51.png