Can anyone point me to a sample script that I can ...
# advancedpdf
n
Can anyone point me to a sample script that I can try to use that allows me to add a custom record sublist to an invoice template? I've tried suiteanswers by searching for Recmach, advanced pdf suitlet, and some other things but can't find anything.
r
Copy code
function buildIntitalFile(record, render, strTransType, templateID , strRecordID){

    switch(strTransType) {
        case 'estimate':
            transTyp = record.Type.ESTIMATE
            break;
        case 'customer':
            transTyp = record.Type.CUSTOMER
            break;
    }
    var rederFileRec;

    //render PDF for sending
    rederFileRec = render.create();
    rederFileRec.setTemplateById(templateID);
    rederFileRec.addRecord('record', record.load({
        type: transTyp,
        id: strRecordID
    }));

    return rederFileRec;


};

function addInvItemsData(query, rederFileRec){

    var itemQuery = query.create({
        type: query.Type.ITEM
    });

    itemQuery.columns = [
        itemQuery.createColumn({ fieldId: 'id' }),
        itemQuery.createColumn({ fieldId: 'custitemgm_longitemdesc' }), //Long Desc
        itemQuery.createColumn({ fieldId: 'itemid' }) ,// SKU
        itemQuery.createColumn({fieldId:'displayname'})
    ];
    rederFileRec.addQuery({
        templateName: 'itemSearch',
        query: itemQuery,
    });
    return rederFileRec;

};
I do somethign like this...
call first function to get base render object.
then call second to add a query to the render record
i can now access second data set via itemSearch
in the PDf template
lastly i render
Copy code
function getPDFFile(rederFileRec, pdfnam){

    var emailPDF = rederFileRec.renderAsPdf();
    emailPDF.name = pdfnam + '.pdf';
    return emailPDF;
};
you may render differently though depnding on contexxt
n
Thanks! @redfishdev
r
<#list itemSearch![] > <#items as itemRecord> <#if itemRecord[2]
snippet of accessing in pdf
n
@redfishdev any chance you have a screenshot of your table in the advancedpdf you could share? I *think we are passing everything into the template correctly but cant get it to render. No errors in the script / suitelet and logs show the data is coming out of the analytics dataset correctly.
r
im not using that one in a convential way as you are but here is another
renderFileRec.addCustomDataSource({ format: render.DataSource.OBJECT, alias: "searchData", data: results });
<#if searchData?has_content> <table style="width: 100%; margin-top: 10px;"><!-- start items --> <#list searchData as invoice><#if invoice_index==0> <thead> <tr> <th align="center" colspan="3" style="padding: 10px 6px;">Invoice</th> <th align="center" colspan="4" style="padding: 10px 6px;">Bill Date</th> <th colspan="12" style="padding: 10px 6px;">Description</th> <th align="right" colspan="4" style="padding: 10px 6px;">Amount</th> <th align="right" colspan="4" style="padding: 10px 6px;">Due Date</th> </tr> </thead> </#if><tr> <td align="center" colspan="3" line-height="150%">${invoice.tranid}</td> <td align="right" colspan="4">${invoice.trandate}</td> <td colspan="12">${invoice.memo}</td> <td align="right" colspan="4">${invoice.amount}</td> <td align="right" colspan="4">${invoice.duedate}<!--<br/>${invoice.daysoverdue} days overdue--></td> </tr> </#list><!-- end items --></table> <hr style="width: 100%; color: #D3D3D3; background-color: #D3D3D3; height: 1px;" /> </#if>
this one I throw on a json object of a SuiteQL query
but here is the one you requested. You can see I am using the second one as a lookup
Copy code
<#if itemName == "Builder Provided">

<#list nonStandardItems![] >
<#items as builderItemRec>
<#if builderItemRec[0] = item.custcolgm_compatibleitem>
<#assign "itemName" = builderItemRec[3]>
<#assign "itemdesc" = builderItemRec[1]>
<#assign "itemSku" = builderItemRec[2]>
</#if>
</#items>
</#list>


</#if>
n
thanks so much!
I'll see if we can get ours to work!
r
best of luck
n
thanks! pulling our hair out right now but we appreciate your examples and quick replies! Owe you one (or a few) 🙂
r
actually built an engine to facilitate it all might try and suiteapp it one day.
n
thats kinda what we are trying to do but our use cases are so unique, not sure we would every get to "productizing" it...hahah
r
forgot I had this until I was working on one tonight.
its a combo of a few posts
throw that is there to see your added data
@NS Admin