Generate a PDF file in the incident form

chandan31
Tera Contributor

Hi All,

 

It is possible to create a PDF file using ui action in the incident form. Once the user save or submit the form all the fields should come the PDF file .

Can anyone provide me the script 

1 ACCEPTED SOLUTION

Amit Pandey
Kilo Sage

Hi @chandan31 

 

Yes, you can do it. You will need create a user which will do pdf export. Create a UI Action like below-

 

AmitPandey_0-1713435426352.png

 

Then Enter below code in the script section of UI action-

 

var rm = new sn_ws.RESTMessageV2();
rm.setHttpMethod('GET');
var url = gs.getProperty("glide.servlet.uri") + current.getTableName() + '.do?PDF&sys_id=' + current.sys_id;
rm.setEndpoint(url);
rm.setBasicAuth('account_id', 'account_password');
rm.saveResponseBodyAsAttachment(current.getTableName(), current.sys_id, current.number + ".pdf");
var response = rm.execute();
var httpResponseStatus = response.getStatusCode();
gs.log(httpResponseStatus);

 

Ensure that you create a user account and enter the id and password for the user account in the 5th line of code.

Optional - Feel free to replace 5th line with below line after setting up 2 system properties, a username and a password that correspond to a user account that is used to generate the PDF.

rm.setBasicAuth(gs.getProperty('pdf.export.username'), gs.getProperty('pdf.export.password'));

 

Please mark my answer helpful and correct.

 

Regards,

Amit

 

View solution in original post

1 REPLY 1

Amit Pandey
Kilo Sage

Hi @chandan31 

 

Yes, you can do it. You will need create a user which will do pdf export. Create a UI Action like below-

 

AmitPandey_0-1713435426352.png

 

Then Enter below code in the script section of UI action-

 

var rm = new sn_ws.RESTMessageV2();
rm.setHttpMethod('GET');
var url = gs.getProperty("glide.servlet.uri") + current.getTableName() + '.do?PDF&sys_id=' + current.sys_id;
rm.setEndpoint(url);
rm.setBasicAuth('account_id', 'account_password');
rm.saveResponseBodyAsAttachment(current.getTableName(), current.sys_id, current.number + ".pdf");
var response = rm.execute();
var httpResponseStatus = response.getStatusCode();
gs.log(httpResponseStatus);

 

Ensure that you create a user account and enter the id and password for the user account in the 5th line of code.

Optional - Feel free to replace 5th line with below line after setting up 2 system properties, a username and a password that correspond to a user account that is used to generate the PDF.

rm.setBasicAuth(gs.getProperty('pdf.export.username'), gs.getProperty('pdf.export.password'));

 

Please mark my answer helpful and correct.

 

Regards,

Amit