[Article] Generating the native PDF export of a record from the backend (script /Flow) and attach it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
27m ago
Summary
ServiceNow has no official server-side API for the form’s Export > PDF option. This article describes an approach that calls the same native PDF endpoint from a server-side script, so the generated PDF is identical to the manual export, with no HTML rebuild.
Use case
Automatically generate the native PDF of a record and attach it to that record, with no user interaction. It can run from a Background Script, Script Include, Business Rule or a Flow Designer custom action.
How it works (high level)
- A server-side script calls the native export endpoint on the instance itself, using RESTMessageV2.
- The request is authenticated with a Basic Auth Profile that uses a dedicated technical user.
- The binary response is saved as an attachment on the source record with saveResponseBodyAsAttachment().
- The script validates the HTTP status and the Content-Type, and removes the attachment if the response is not a valid PDF.
Important notes
- The ?PDF endpoint is not a documented or supported API. Please validate it after upgrades.
- Basic authentication may be blocked by Basic Auth Restriction, so the technical user needs to be authorized by your security team.
- The PDF content follows the ACLs and the view of the technical user, not the user who triggered the script.
- Use a dedicated account with least privilege and never hardcode passwords. Keep them in the Basic Auth Profile.
Attached documentation
The full step-by-step guide is attached in two versions (English and Portuguese). It covers the technical user setup, Basic Auth Restriction, the Basic Auth Profile, the complete script, validation, troubleshooting and production considerations.
Feedback and improvements are welcome. If you have found another approach for this, please share it in the comments.
