Would appreciate a quick sanity check from anyone ...
# advancedpdf
t
Would appreciate a quick sanity check from anyone that may have some experience with this: the situation is needing to use a script with the native print function on an invoice. I’ve created countless scripts and I’ve worked with advanced templates quite a bit, and I’ve created some custom standalone templates with custom data sources etc. However, I don’t believe it’s possible to use any scripting (aside from what BFO/FreeMarker provide within a template) with the native print function — meaning the resulting pdf that is rendered using the advanced pdf template selected on the invoice’s custom transaction form config. You can attach custom code to the form for instance, or deploy client scripts to a record type of course, and this is helpful for form or client side logic. But there’s nothing similar with an advanced template right? The overall objective is to be able to essentially include a statement within the invoice pdf, showing open transactions and the aging table on the page(s) after the first pdf page(s) that show all the usual info for an invoice. There are some tricks with custom fields driven by formula or saved search that can then be included in a template… but including search results for open transactions and the level of control needed to do that, does not seem possible using the native print on the invoice which simply renders the template selected on the transaction form. This is definitely possible for a standalone template or for any template that you render within your own suitescript, but I’m trying to have this work for the native print. If anyone can confirm this or knows if I’m wrong here, would appreciate any input. Thanks!
c
The native print button only prints the selected advanced pdf thats on the form itself. If you want custom data sourced anything, you have to add your own button and render the PDF yourself. You'd need a custom PDF here for the invoice that gets all of the aging info you need and displays it in a custom data source PDF. You can include a pdf within a pdf though using the pdfset bfo tag.
t
Thanks @creece, there’d be no way to include the custom data source pdf within the pdf that is rendered by clicking the native print menu option, right?
I mean, that’s the crux of the matter, really. On the native print pdf template, we’re limited to current record and a couple others (company info, subsidiary, etc), but no further logic beyond those and using BFO/FreeMarker
Full custom route is easy enough though on its own. The reason for trying to get the native print pdf to incorporate more info is so that an existing integration sync that gets the invoice pdf (based on the form’s pdf template) would not need to be changed.
I haven’t seen the integration being used, I just know it renders the form’s selected pdf template. So if the pdf requires that additional info, it seems like the integration will need to be updated so it can sync the pdf in a different way, a way that allows full control over the rendering, so custom data sets etc can be used
Just wanting to sanity check that I wasn’t missing something easier than that route.
It would be great for NetSuite to allow attaching a script to a template, similar to how you can for a form, so then the native print menu option could render a pdf that is more customizable since real scripting could live alongside the template
c
This sounds like a perfect case for the custom data sourced. The only thing you could potentially do is on save of the Invoice, generate the aging report PDF and save it as a reference on the Invoice. Then use pdfset on the PDF attached to the form that will include that PDF if its set. The main issue being that the data could get stale on the Invoice if it isn't saved prior to printing which is probably not a great solution. The custom route def seems the way to go here.
t
Solid idea on saving the pdf and then referencing it, but agreed that data could get stale and unlikely the record is saved to refresh that when the integration syncs the pdf. Would be nice to use a custom field that does not store value that could return the required data and then embed that somehow, but still seems like that sort of hackery wouldn’t work out great. But yeah, I think we’ll have to take a look at the integration and adjust it to sync a custom data source based template, which is really the best way to render a pdf with the desired data. Thank you for the input and being a sounding board on this.
t
your idea about having a non stored value custom field in the record is on the right track. What I did before is to create a long text field to store a JSON string that is populated on UE before load. You can then use that value in you pdf template. Just use freemarker eval_json to parse that value https://freemarker.apache.org/docs/ref_builtins_expert.html#ref_builtin_eval_json
t
Thanks for the reply @tech_ph2019 - I’ll definitely test this out as well. The current desired pdf with all its extra data is implemented in NetSuite with a suitelet and the suitelet is launched by a button on the invoice. The template strings are all script params rather than an actual advanced template being used. It’s a little messy. But this works as needed within the UI. However, there’s now a need to sync the pdf outside of NetSuite. I didn’t build the suitelet or the integration, but helping now with the updates to get this working as it needs to — if the integration can be updated to grab the rendered pdf from the suitelet, that may be the easiest route. But if that’s more trouble than it’s worth, then figuring out the eval and parsing of a json string in a field that doesn’t store value sounds like a good alternative to try out.
d
@tech_ph2019 unfortunately we can't use the
?eval_json
built-in yet, it's a 2.3.31 (Feb '21) feature and NetSuite is still using 2.3.26-incubating (March '17) I agree with Chris that it should really be a custom data pdf, but if you decided to go with a non-stored JSON string field, you would have to use the
?eval
built-in (noting that it is insecure for untrusted sources)
👍 1
t
@David B yes, you are correct, I checked my old template and I did use eval instead of eval_json. Thanks for pointing that out
👍 1