Unable to see record data in pdf when pdf generated via sn_ws.RESTMessageV2 API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Hi all,
I'm trying to auto-generate PDF of my table record so i created a business rule to have it triggered upon certain changes in the record.
I followed this article Generate PDF and attach to the record - ServiceNow Community and was able to generate the PDF successfully, however i'm not sure why the PDF generated is not showing my record data BUT if i access the setEndpoint url in the browser (with the user i used for authentication), the pdf generated is able to show the record data (i also confirmed via Access Analyze that the user can see all data).
Is there some configuration that i'm missing?
Also note,
- the sys_user i'm using has admin role + web_service_admin role and
- my tables have "Allow access to this table via web services" enabled
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
which user you are using to consume the REST Message?
share your script
what that pdf contains?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Thank you for the quick response.
The script is something like below
var basicAuthProfileSysID = gs.getProperty('com.customer.pdf.authprofile');
generateAndStoreAttachment('incident', '12345678900000000000', 'Default', current.sys_class_name, current.sys_id,'Incident_Export.pdf', basicAuthProfileSysID);
/**
* Gets a PDF from a record form view and stores it as an attachment to the same record.
* Uses RestMessageV2 for getting the attachment via HTTP Call.
*
* All parameters are mandatory.
*
* {String} pdfTable Table of the record to be generated.
* {SysID} pdfSysID Sys ID of the record.
* {String} view View that should be used for generation of PDF
* {SysID} attachToTable Class name/table name to which the record should be attached.
* {SysID} attachToSysID Sys ID of the record that generated file should be attached to
* {String} fileName Target file name.
* {SysID} authProfileSysID SYSID of the profile to be used for authentication.
* @return null
*/
function generateAndStoreAttachment( pdfTable, pdfSysID, pdfView, attachToTable, attachToSysID, fileName, authProfileSysID ) {
var r = new sn_ws.RESTMessageV2();
r.setHttpMethod('get');
r.setEndpoint('https://'+gs.getProperty('instance_name')+'.service-now.com/' + pdfTable + '.do?PDF&sys_id=' + pdfSysID + '&sysparm_view=' + pdfView);
r.setAuthenticationProfile('basic', authProfileSysID);
r.saveResponseBodyAsAttachment(attachToTable, attachToSysID, fileName);
var response = r.execute();
//response.getStatusCode();
}
I believe the script was run successfully. But i feel i am probably missing some configurations in my instance to allow the table data to appear via server-side pdf generation.
>what that pdf contains?
It will contain the record details (technically user can right click the record header and export as pdf - that is the pdf we want to auto-generate)
Example of pdf not showing the data
>which user you are using to consume the REST Message?
Self-created sys_user
Note, i only ever created a profile at "sys_auth_profile_basic", nothing else
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
the current PDF which is getting generated and attached contains an empty page?
remember the user who is being used as API user should have read access to that INC via table.None READ ACL and also remember there is query Business rule on incident table.
Did you try with admin credentials in the basic auth profile and see if it works and shows data in pdf?
If yes then it's definitely ACL or Query BR issue.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
>the current PDF which is getting generated and attached contains an empty page?
It looks like this:
>remember the user who is being used as API user should have read access to that INC via table.None READ ACL and also remember there is query Business rule on incident table.
Yes, i've confirmed they have table.None READ acl already and the business rule is confirmed to be running as the blank data pdf was generated
>Did you try with admin credentials in the basic auth profile and see if it works and shows data in pdf?
Yes i've tried, no data is showing