Email notification from a transform map

stevewilson
Kilo Contributor

We have an inbound email action that takes an excel attachment and runs a transform map. I have an onBefore script that is checking to make sure a few fields are in the proper format. For example, make sure the date is in a certain format and that the IP address is in a valid range. All of this is currently working. Our customer is wanting an email that contains the errors so they can fix them. So if the date is incorrect they would get an email saying something like "row 10 - invalid date format" or "row 5 - ip address is invalid".

My question is how can I send out an email and save the information that was incorrect from a transform map script? Most likely there could be multiple rows with errors from a single transform of the email attachment.

13 REPLIES 13

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Your inbound email action is likely not waiting on the transform to complete. You will likely have to create a business rule on the import set table that runs when the state changes to processed and have the script summarize the errors and send out the email.


Exactly what Michael said, you need to write an After Insert BR on the sys_import_set_row table.


You will have to trigger your Notification firing Event through a BR when the state of the Import Set Row record turns to Error and the Transform Map is the transform map you are using for this.



You can pass on the Error code in the email notification body. Please note, notifications will be triggered for each and every Error.


ohhgr
Kilo Sage
Kilo Sage

Hi Steve,



If I understand correctly, you want to trigger a mail when all the rows have been transformed with details for all the failed rows.



For this, you can use a transform map scoped variable with an approach like below.



1 ) Define a variable in the onStart script for the map. ((Do not encapsulate it in a function, keep it outside all functions so that other scripts can access the same).


2 ) Update the content of this variable each time you find any error in your onBefore script.


3 ) Use the same variable to pass the accumulated error data to the email notification in onComplete transform script, using gs.eventQueue() function.



Hope that helps.


-Mandar


Thank you for the reply, you got me on the right path. Still working on completing all the validations and error messages for the fields but it looks like I can find everything I need for an email notification by using events and the gs.eventQueue() function.



Would I being using a business rule to trigger the email notification and grab the error messages in the event queue?