- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2024 08:19 AM - edited ‎09-02-2024 10:16 AM
Hello!
I have a requirement to auto-generate and attach a PDF document to an HR case once the Record Producer is submitted.
I was able to achieve that with HR Document Templates by creating a Flow that would look up PDF draft (created by leveraging 'Automatically Create Draft Document' Case Option) -> Look up attachment where this draft record is referenced -> Copy attachment to the case record.
I would like to migrate this logic to Document Templates since HR Document Templates are being deprecated.
For other reasons, as a Type, I'd like to use HTML Template.
Can you please suggest how it would be possible to implement automatic document generation using Document Templates?
I checked the Generate PDF Document Action in Flow Designer, but that seems to work only for Tasks which my case does not have.
The 'Automatically Create Draft Document' Case Option seems useless with Document Templates and I haven't found the logic how to move the documents 'behind the scenes'. I know that for Document Templates there is the option 'Automatically Initiate Document tasks', but again seems to be connected to tasks.. How can I trigger document generation using HTML documents from Document Templates?
Any tips appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2024 05:58 AM
The issue was solved by using this API:
//recordId - Sys ID of the target record. This record must be from the table defined in the document template.
//documentTemplateId - Sys ID of the document template to use for pdf generation.
//pdfName - Name of the pdf generated
new sn_doc.GenerateDocumentAPI().generateDocumentForTask(recordId, documentTemplateId, pdfName);
as mentioned in SN Documentation: Document generation methods (servicenow.com)
I created a custom Flow Action very similar to Generate PDF Template that uses the API mentioned above and called it for the HR Case, filling the fields with Case Sys ID and Document Template Sys ID.
Also checked that it works both for PDF and HTML documents created with Document Templates.
This is how the process would look like in a business rule (with condition Document Template is Not Empty):
(function executeRule(current, previous /*null when async*/ ) {
var templateSysId = current.document_template.sys_id;
try {
var pdfName = current.document_template.name + "-" + current.subject_person.name;
var pdfSysId = new sn_doc.GenerateDocumentAPI().generateDocumentForTask(current.getUniqueValue(), templateSysId, pdfName);
} catch (e) {
gs.error("Error message: " + e.message);
}
})(current, previous);
After executing the script, a PDF is generated and attached to the case.
The logs still show an error message "Document task not found", but this is the cleanest solution I've found so far. If someone has a better suggestion, please share!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2025 03:37 AM
Hi @Chandana E S ,
1.After the case gets submitted and assigned an hr agent, agent should select the document template and start work on the case.
2.That means you have document template placed and state is in work in progress and the assigned to is You only, that means logged in user is the assigned to.
3. Once case move to work in progress you can see preview document Ui action once you click on it it give you options like Cancel, edit, generate and initiate document tasks.
am attaching screenshot FYI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2025 08:05 AM
I want attach generated pdfs to RITM can someone help me with script to use in flow designer action?