Convert submitted RITM with submitted values into PDF and send an email to requestor

Meenal Gharat
Giga Guru

Hello all,

 

I'm trying to convert submitted RITM to PDF and attach that PDF on RITM and send an email to the requestor.

 

Tried below script It is working with Background script but not with BR, I have written After Insert BR.

 

var pdfUtil = new sn_pdfgeneratorutils.PDFGenerationAPI;
var fileName = "RITM_"+current.number+"_Details.pdf";
 
var html = "<html><body>";
html += "<h2>Submitted Request :"+current.number+"</h2>";
html += "<table border ='1 cellpadding ='5' cellspacing='0'>";
html +=  "<tr><th>Field</th>Value</tr>";

//Get Variables from RITM
var variables = current.variables;
for (var key in variables){
    if (variables.hasOwnPropert(key))
    {
        var varLabel = variables[key].getLabel();
        var varValue = variables[key].getDisplayValue();
        html += "<tr><td>"+varLabel+"</td><td>"+varValue+ "</td></tr>";
    }

    }
    html +="<table>";

var hfInfo = new Object();
//hfInfo["HeaderImageAttachmentId"] = gs.getProperty('sn_cheque_collection_image_id');//sys_id of attachment
hfInfo["PageSize"] = "A4";
hfInfo["GeneratePageNumber"] = "false";
var hfi=new Object();
hfi['PageOrientation']= 'POTRAIT';
hfi["GeneratePageNumber"] = "false";
//hfi["HeaderImageAttachmentId"]=gs.getProperty('sn_cheque_collection_image_id');//sys_id of attachment
var result = v.convertToPDFWithHeaderFooter(html, "sc_req_item",current.sys_id, filename,hfi,'', hfInfo);
 
Kindly assist.
 
Best regards,
Meenal
4 REPLIES 4

Anil Nemmikanti
Giga Guru

Hi @Meenal Gharat ,

In the below code.

 

"v.convertToPDFWithHeaderFooter"
 
v variable is not defined in the code. Please check. Thanks.

 

Ehab Pilloor
Mega Sage

Hi @Meenal Gharat,

Please try the following lines of code with 2 changes.

var pdfUtil = new sn_pdfgeneratorutils.PDFGenerationAPI;
var fileName = "RITM_"+current.number+"_Details.pdf";
 
var html = "<html><body>";
html += "<h2>Submitted Request :"+current.number+"</h2>";
html += "<table border ='1 cellpadding ='5' cellspacing='0'>";
html +=  "<tr><th>Field</th>Value</tr>";

//Get Variables from RITM
var variables = current.variables;
for (var key in variables){
    if (variables.hasOwnProperty(key)) // 3rd change
    {
        var varLabel = variables[key].getLabel();
        var varValue = variables[key].getDisplayValue();
        html += "<tr><td>"+varLabel+"</td><td>"+varValue+ "</td></tr>";
    }

    }
    html +="</table></body></html>";

var hfInfo = new Object();
//hfInfo["HeaderImageAttachmentId"] = gs.getProperty('sn_cheque_collection_image_id');//sys_id of attachment
hfInfo["PageSize"] = "A4";
hfInfo["GeneratePageNumber"] = "false";
var hfi=new Object();
hfi['PageOrientation']= 'PORTRAIT'; //1st change
hfi["GeneratePageNumber"] = "false";
//hfi["HeaderImageAttachmentId"]=gs.getProperty('sn_cheque_collection_image_id');//sys_id of attachment
var result = pdfUtil.convertToPDFWithHeaderFooter(html, "sc_req_item",current.sys_id, fileName,hfi,'', hfInfo); //2nd change

 Regards,

Ehab Pilloor

 

Edit: Made some corrections after closer inspection, please try and see if it works.

Tried the above still no luck.

checked logs it is entering in BR 

 

Is something else we need to check?

 

@Meenal Gharat, you can disable BR in the script by adding 

current.setWorkflow(false); //add after 2nd line

 Please note the BR process and see if its relevant in this activity. Also I have made few more corrections in the code posted earlier. Please try and see if it works. 

 

Regards,

Ehab Pilloor