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 script issue -- scoped application

_navin9898
Tera Expert

Hi Team,

I have requirement where I need to check if a source field is empty in an excel file while import and trigger a notification based on that.

For example: I am receiving Task number(s) in excel which needs to be processed further. Now there are some scenarios where this file could be empty as you can see in attached; in that case I need to trigger a notification to relevant people.

 

I am seeing an issue where I am not able to read 'Task number' field using onbefore transform map script. If value of Task number is present then onbefore script is working, however if field is empty and we try to read the value by using below and try to print the same, it is not retuning anything.

 

var task_number = source.u_task_number;

gs.info(task_number);

 

My assumption is that if file is empty, above code should return empty value/string.

Could someone please redirect me to the right direction and let me know what I am doing wrong?

 

Best Regards,

Naveen

 

 

 

 

 

 

 

8 REPLIES 8

Hi @Ankur Bawiskar 

Please find below actual code which is not working.

 

var task_id = '';
task_id = source.u_servicenow_task_id;
if(task_id == '' || task_id == null)

{
gs.eventQueue('custom_app_prefix.servicenowTaskUpdate',source);

}

 

Best Regards,

Naveen

 

@_navin9898 

did you check what came in task_id in logs?

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

Harish Bainsla
Kilo Patron
Kilo Patron

var task_number = source.u_task_number;
if (task_number ==null || task_number == undefined || task_number == "") {

gs.info("Task number is empty");

} else {

gs.info("Task number: " + task_number);
}

Voona Rohila
Mega Patron
Mega Patron

Hi @_navin9898 

you mentioned that My assumption is that if file is empty, above code should return empty value/string. - If the file is empty then the onBefore script will not run,It executes at the start of a row transformation and before the row is transformed into the target row

 

You can use onStart which executes at the start of an import before any rows are read (The same code which you wrote will not work if onstart)


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP