Fill fields in a PDF using API "PDFGenerationAPI"

SNOW BOT
Tera Contributor

Hello Community

 

I am trying to fill the PDF using "PDFGenerationAPI" as described in below link 

 

https://www.servicenow.com/community/developer-articles/fill-fields-in-a-pdf-using-quebec-api-quot-p... 

 

 

and getting the response as:

 

Script: {
	"message": "No Form associated with pdf to fill. attachmentSysId: def6f8331b2af5d0b69bcbbe034bcbd3",
	"status": "failure"
}

 

Anybody has faced the same problem please help me out

PDF has attached

 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@SNOW BOT The testing.pdf you are using is not a fillable PDF hence the PDFGenerationAPI is not able to fill data in it. A fillable PDF is a PDF where the fields can be edited, the PDF you shared contains the images of two text fields and can't be edited using any PDF tool. You can use https://www.sejda.com/pdf-forms to create a fillable PDF form.

 

Also, attaching the fillable version of your PDF, which you can use for the testing purpose.

 

Please mark this answer helpful and correct if it manages to address your question.

View solution in original post

5 REPLIES 5

Sandeep Rajput
Tera Patron
Tera Patron

@SNOW BOT The testing.pdf you are using is not a fillable PDF hence the PDFGenerationAPI is not able to fill data in it. A fillable PDF is a PDF where the fields can be edited, the PDF you shared contains the images of two text fields and can't be edited using any PDF tool. You can use https://www.sejda.com/pdf-forms to create a fillable PDF form.

 

Also, attaching the fillable version of your PDF, which you can use for the testing purpose.

 

Please mark this answer helpful and correct if it manages to address your question.

@Sandeep Rajput 

 

Thank you for the response, I have tried the same file shared by you 

it is showing error below:

 

*** Script: {
	"message": "No editable field exists with specified name. Please check and try again. field_name : RollNo",
	"status": "failure"
}

 

Here is my code:

var fieldMap = {

    "RollNo" : "Company X"

};

// Execute API

var v = new sn_pdfgeneratorutils.PDFGenerationAPI;

var result = v.fillDocumentFields(fieldMap, "24d181ff1baaf5d0b69bcbbe034bcb80", "sc_req_item", "4d83c0ffdba6f114f01acafc1396197c", "test");

 

@SNOW BOT Please try with the following code.

 

 

var fieldMap = new Object();
fieldMap["text_1ayxc"] = "Roll 12345";
fieldMap["text_2lxcz"] = "John Doe";

var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
var result = v.fillDocumentFields(fieldMap, '24d181ff1baaf5d0b69bcbbe034bcb80', "sc_req_item", "4d83c0ffdba6f114f01acafc1396197c", "test");
gs.info(JSON.stringify(result));

Here is the end result.

 

Screenshot 2023-11-24 at 12.35.32 AM.png

 

@Sandeep Rajput 

 

My form contains the 20+ fields & I know we can get the backend name of fields using: 

 

var result = v.getDocumentFields("attachmentSysId");

 

 

After executing above script I got below response:

 

"fields":["text_1qjdq","text_1qjdq.1","text_2fblh","text_2fblh.1","text_3dors","text_3dors.1","text_4uxvb","text_4uxvb.1","text_5vrge","text_5vrge.1","text_6uuzm","text_6uuzm.1","text_7eani","text_7eani.1","text_8ioxx","text_8ioxx.1","text_9uwkk","text_9uwkk.1","text_10ahk","text_10ahk.1","text_11yfoq","text_11yfoq.1","text_12fpo","text_12fpo.1","text_13vztg","text_13vztg.1","text_14eorl","text_14eorl.1","checkbox_15isbv","checkbox_15isbv.1","checkbox_16pkke","checkbox_16pkke.1","checkbox_17vjec","checkbox_17vjec.1","checkbox_18ixgn","checkbox_18ixgn.1","text_19yntu","text_19yntu.1","checkbox_20chlr","checkbox_20chlr.1","checkbox_21jbmq","checkbox_21jbmq.1","checkbox_22oszi","checkbox_22oszi.1","text_23asjf","text_23asjf.1","text_24iugl","text_24iugl.1","text_25blxs","text_25blxs.1","checkbox_26lffn","checkbox_26lffn.1","checkbox_27sxrq","checkbox_27sxrq.1","checkbox_28epso","checkbox_28epso.1","checkbox_29vozn","checkbox_29vozn.1","text_30zkea","text_30zkea.1","text_31xtlw","text_31xtlw.1","text_32ioqp","text_32ioqp.1","checkbox_33xznx","checkbox_33xznx.1","checkbox_34ufnr","checkbox_34ufnr.1","checkbox_35uewb","checkbox_35uewb.1","checkbox_36gqkg","checkbox_36gqkg.1","checkbox_37hawp","checkbox_37hawp.1","checkbox_38mhgg","checkbox_38mhgg.1","text_39nyuy","text_39nyuy.1","checkbox_40ojfn","checkbox_40ojfn.1","checkbox_41cqun","checkbox_41cqun.1","checkbox_42yath","checkbox_42yath.1","text_43jyay","text_43jyay.1","text_44hvma","text_44hvma.1","text_45ejuh","text_45ejuh.1","text_46vpw","text_46vpw.1","text_47mcsi","text_47mcsi.1"],"status":"success"}

1) Just wanted your guidance here, how could I know which backend field name indicates the field name of form?
2) Can we update the backend name of fields with the Actual field name on form