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.

Transform Map: How to display a custom error when a coalesce field is empty?

Med99
Tera Contributor

Hi everyone,

I’m working on a Transform Map where one of the fields is set as coalesce.
I would like to show a custom error message in import_log when this coalesce field is empty in the source data.

I tried adding this check in the onBefore script:

 

if (!source.u_code || source.u_code.toString().trim() === '') {
ignore = true;
source.sys_import_state_comment = "Obligatory field missing: Code";
}


However, this script is never executed when the coalesce field is empty.
Instead, I always get ServiceNow’s standard error:

"Unable to resolve the target record, coalesce field values are not present..." in sys_import_set_row

It seems the Transform Map engine throws this error before the onBefore script runs, so my message never appears.

How can I handle this situation and display my own validation message ?

Thanks in advance!

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Med99 

try to use before insert BR on your staging table

something like this

(function executeRule(current, previous /*null when async*/ ) {
    if (!current.u_code || current.u_code.toString().trim() === '') {
        current.state = 'rejected';
        current.comments = 'Obligatory field missing: Code';
    }
})(current, previous);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

didn't work , I still get the servicenow standard message appearing