- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2023 03:44 AM
Hi ServiceNow Community,
I'm stuck on a requirement and need your help to achieve that.
I need to send an attachment using the email notification in ServiceNow,
while adding the attachment to the email body i.e.(Message HTML box) I need to auto-populate the user details on the related section of the PDF attachment.
below is the sample PDF attachment.
can anyone have an idea how to achieve that?
I'm trying with the below email script to achieve that but it's not working.
@Anil Lande @Sandeep Rajput @Community Alums @Ratnakar7 @Chuck Tomasi @asifnoor @Sam Dey @Sam Dey1
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2023 06:30 AM
@Kunalo7o8 Looks like you are not providing the correct field name for name field in the fillable PDF. I did some test runs to use this API in my background script and it works just fine for me.
Here is the sample script I used.
var list = new GlideRecord("incident");
list.addEncodedQuery("sys_id=e5cedec14776611092c98021336d438d"); //Change this with your incident sample record.
list.setLimit(1);
list.query();
while (list.next()){
var attachment = new GlideRecord('sys_attachment');
if(attachment.get('table_sys_id',list.getValue('sys_id'))){
gs.info(attachment.getValue('file_name'));
var pdfUtils = new global.GeneralPdfUtils();
gs.info(pdfUtils.getPDFFields(attachment.sys_id));//Provides you the names of fields within PDF
var jsonForPDF = '{"Check Box1":"true","Check Box2":"true","Address":"123 MG Road","Text6":"This is fillable","Text5":"PDF","Name":"Tom Hanks","Group6":"","Dropdown3":"","Dropdown2":"","Dropdown1":"","Check Box3":"false","Button7":"","Check Box4":"true"}';
pdfUtils.prefillPdf(jsonForPDF,list.getValue('sys_id'),attachment.getValue('sys_id'),'incident','filled_pdf'+Math.random()+'.pdf');
}
}
In order to be sure about the field names present in the fillable PDF, use the following method.
pdfUtils.getPDFFields(attachment.sys_id); //Provides the list of fillable field names in a JSON format.
Here is how my fillable PDF looks when it is empty.
Here is how it looks when the data is filled into it using the script shared earlier.
Attached is the fillable PDF for your reference. Test it by attaching it on any incident record and use the sys_id of that incident on line of two of this script.
list.addEncodedQuery("sys_id=e5cedec14776611092c98021336d438d"); //Change this with your incident sample record.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2023 11:06 AM
@Sandeep Rajput I'm trying with the above edits can you please check once? why I'm getting the null?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2023 07:34 PM
@Kunalo7o8 Looks like the PDF you are using is a non fillable PDF, can you test your script with the PDF attached with this post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 07:22 PM
@Sam Dey1 can you guys please tell me about the fillable pdf I did some research on that but couldn't find anything is it feature in servicenow or anything else.
Please tell me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2023 11:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2023 06:45 PM
Hi Kunal,
From the PDF screenshot you have shared it seems that is a non-fillable pdf. So to automate the pdf fill- you have do define a pdf file where you name the fields that you want to populate, for e.g. -
First create a PDF where you put a field name called "name" and that field is a text box. then you run the api to fill-up the field called name it should do the work.
So essentially you have to create a fillable pdf first