HTML code being returned when previewing the document template of type HTML

Veena-EeshB
Tera Contributor
HTML code being returned when previewing the document template of type HTML .I was testing the document generation through API script , but the pdf which got attached to the record shows with HTML tags .  i have used some plain single line text to print . And even when i click on preview on HTML document template , it shows the same .Can you please let me know what am I missing.
 
 
var recordId = '52fc****;
var documentTemplateId = '252a***';
var pdfName = 'INC_Template.pdf';
new sn_doc.GenerateDocumentAPI().generateDocumentForTask(recordId, documentTemplateId, pdfName);
1 ACCEPTED SOLUTION

Ehab Pilloor
Giga Sage

Hi @Veena-EeshB,

 

Have you added HTML code directly into the HTML canvas or via source code?

EhabPilloor_0-1793013794856.png

 

I have implemented a document creation and it works fine for template type as HTML template. I dont see any issues. I have created HTML code and built my document template. Your script is correct too.

Edit: assign the creation of template to a variable, not related to the issue but a good practice.

var result = new sn_doc.GenerateDocumentAPI().generateDocumentForTask(recordId, documentTemplateId, pdfName);

 

Regards,

Ehab Pilloor

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron

@Veena-EeshB 

share your content within that template

Thanks for the reply Ankur. I was doing html coding in the html editor which is why it was behaving in such way , my bad. Thanks again

Hi Ankur ,

 

I am going through another hurdle 'Document generation Api works from background script but not through HR flow or BR'. Can you please let me know your throughts

 

I have tested the document generation through background script -

var recordId = '021e42bfc348d390f52****';
var documentTemplateId = '252abf1b938***';
var pdfName = 'CFTC.pdf';
new sn_doc.GenerateDocumentAPI().generateDocumentForTask(recordId, documentTemplateId, pdfName);
 
but running this through Business rule using current.sys_id , its not generating the document at all. 
I have also tried creating the flow and using 'generate pdf document' action , and when checked the executions, it comes as completed and no errors but document is not being generated at all. I tried checking the restricted cross scope  and allowed there as well. Tried creating template and BR in global scope ,but that didnt work either. 
 
Appreciate any guidance here as I'm stuck.
 
BR log gives null for line Document result:
(function executeRule(current, previous /* null when async */ ) {
gs.info("inside attach br");


    var templateName = 'CFTC_Attestation.pdf';
    var recordId = current.sys_id;
    var documentTemplateId = '252abf1b938093509f4d3ddfebba10f6';
   
    var result= new sn_doc.GenerateDocumentAPI().generateDocumentForTask(recordId, documentTemplateId, templateName);
    gs.info("Document result: " + JSON.stringify(result));
    gs.info("br complete"+current.sys_id);

})(current, previous);
 
Thanks 
Veena

Hi @Veena-EeshB ,

Check the document template

 

In BR the template sys_id = “252abf1b938093509f4d3ddfebba10f6” but in the flow the Document template sys_id is “aa48beffc3c01790f521990c050131c8” and check if the template is belongs to “sn_hr_core_cftc_survey_answer”.

Kindly mark Helpful if the issue is fixed.

Regards
Sudhanva Chandra D
Certified ArchX || 8x ServiceNow CIS