This works fine though so it is definitely not the...
# suitescript
n
This works fine though so it is definitely not the template:
Copy code
response.writeFile({
 file: render.transaction({entityId: parseInt(params.record_id), printMode: render.PrintMode.PDF}),
 isInline: true
 });
But I cannot use this as I have to pass in data via custom data source.
n
you have serverResponse and response is that just a typos in Slack?
n
Yeah, it's a typo because I copied that part from NS docs as I removed it from my original script.
👍🏻 1
b
what you have shared so far has not actually excluded the template
render.transaction adds additional data sources besides the record
nor have you shared enough information to show that render.transaction is even using
CUSTTMPL_SALE
, you have only showed that the sales order's form has a valid template
n
@battk my question is in 2 parts. Let me share the previous part as well.
Copy code
function printPDF(params) {
    var renderer = render.create();
    renderer.setTemplateByScriptId({
       scriptId: 'CUSTTMPL_SALE'
    });
    var lookupResult = search.lookupFields({type: search.Type.VENDOR, id: params.vendor_id, columns: ['altname']});
    renderer.addCustomDataSource({
       format: render.DataSource.OBJECT,
       alias: 'data',
       data: {
          vendor_id: params.vendor_name,
          vendor_name: lookupResult.altname
       }
    });

    renderer.addRecord({
       templateName: 'record',
       record: record.load({
          type: params.record_type,
          id: parseInt(params.record_id)
       })
    });

    return renderer.renderAsString();
}
Copy code
var fileObj = printPDF(params);
response.setHeader({
    name: 'Content-disposition',
    value: 'filename="' + params.tran_id + '"'
});
var pdfFile = render.xmlToPdf({
    xmlString: fileObj
});

response.writeFile({file: pdfFile});
But this works fine:
response.write({
output: renderer.renderAsString()
});
(edited) I have tested printing the template using the code below and that works fine as well.
Copy code
response.writeFile({
 file: render.transaction({entityId: parseInt(params.record_id), printMode: render.PrintMode.PDF}),
 isInline: true
 });
b
same answer,
n
The template is getting printed from the native Print function, if that helps.
and if I print it in the browser, that is also working:
response.write({
output: renderer.renderAsString()
});
b
rendered.renderasString doesnt actually pass to bfo
everything you have shared so far suggests that something is wrong with the template
n
so why does the native print function works?
from the Print button on the transaction.
b
the native print button is equivalent to renderer.transaction
it adds a bunch of data sources, and escapes xml
n
I see...
b
the renderer does not
n
should I try by removing the code which is using custom data source?
b
you also havent really shared anything to suggest that the sales order's form uses CUSTTMPL_SALE
only that it does have a form with a valid template
n
I have verified the form again just now, it is using the template that I have created.
b
whats the template
n
CUSTTMPL_SALE
Sale PDF/HTML Template
b
the actual templte
the name or id mean very little to me
n
Due to confidentiality reasons, I cannot share the template.
In the data sources in the template, there is record, subsidiary, data (my custom source), and translation handle.