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

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

Thank you for the reply . My bad, I was coding html in html editor and not on source code. Thanks again

Hi Ehab ,

 

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,

 

You can tag me so that I get notification, I have used this code which works for me

           var result = new sn_doc.GenerateDocumentAPI().generateDocumentForTask(
           current.getUniqueValue(), // where to attach
           "b28434fd9f4bc310092d88d86924abbd", // html template 
           documentName // file name
           );

 

Regards,

Ehab PIlloor