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.

Mike S1
Tera Contributor

In my last post, I talked about using the server script on the Record Producer to evaluate an attached Excel File. Now I'll attempt to add a scanner when the file is attached to the attachment field on the form. This process uses the code from the basic example in the documentation on GlideExcelParser here.

 

To start, I set up a script include to take in the sys_id of the attachment, break it apart using GlideSysAttachment and GlideExcelParser, and then roll through each row looking at column 1 in the Excel file. It just does a name query against the HR Service table and returns a list of invalid row numbers if it finds any.

 

MikeS1_0-1759925993124.png

MikeS1_0-1759926716399.png

 

Next, I added a Catalog Client Script on my Record Producer to call the Script Include onChange of the File variable. I'm passing in newValue which is just the sys_id of the attachment that would be added to the form, 

 

MikeS1_1-1759925993125.png

 

Then I mocked up a test input file with some invalid HR Service names. The script will check for them in column B, or [1] in the parser script.

 

MikeS1_2-1759925993126.png

 

Attaching that file to my form triggered the call to the Script Include to do the validation. I received a list of numbers back from the script so I displayed that in the error box.

 

MikeS1_3-1759925993126.png

 

Running my original valid file passed my scan successfully.  

 

MikeS1_4-1759925993127.png

 

 

There's a lot more that could be done with file checks, but this hopefully provides some basic idea of how you can monitor the attachments added to the system when a specific template is needed.