- 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
‎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
‎06-26-2025 04:37 AM - edited ‎06-26-2025 04:38 AM
Hi @AijaRe
I have created a new service with case options as automatically create draft document and attached record producer also. After this i have setup fulfillment type as service activity and task with template as e-signature and assigned to subject person in the case fields of the template. Now i have created a new document template with HTML type with some text. now i have created a case with the same service and document template is showing empty. if am not wrong document template should be auto filled and then pdf should generated.
to test verify this i have created a case but the document template field is showing empty and i tried by manual selection then also and update d still showing document could not be loaded contact your administrator. Can you help where am missing this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2025 09:38 AM
Hi,
A template should be created for the HR service and the document template that you created should be added in that case template. Please recheck if you have tied the HR service and the document template together with the above approach.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2025 01:06 AM
Hi @Chandana E S ,
Thanks for the response. Am able to find the solution for my issue. It was just case options that i need to update.