Does anyone know if it's possible to access a rela...
# suitescript
m
Does anyone know if it's possible to access a related record's sublist values in an advanced PDF template?
It's a custom field with type Record, which is referencing the vendor bill on an invoice. I want to access the vendor bill's item data but it doesn't seem to be accessible
j
in my experience, it’s not accessible
☝️ 1
what I ended up doing is dumping the text I needed into a JSON field on the parent record
d
That's one way to do it, and would mean you don't have to script the PDF creation. The other way you could do it is to script it with
N/render
and add the vendor bill's data as a custom data source
but if you're only needing one or two fields from the vendor bill, use a custom field sourcing the data you want onto the invoice (or even for lots more fields, use Jen's solution of having some sourced JSON string on the invoice)
m
for scripting it what script type would that be? Is there an advanced pdf template script? Or would it be a suitelet with n/render?
d
honestly Jen's solution seems easier. It would be a non-stored field/fields, so not bloating your DB and would be simple to setup
m
Would it require a user event script to populate the JSON field? Or is this something you are suggesting I could grab via the advanced PDF that would cause the vendor bill to dynamically generate the data (since it's non-stored)?
j
ummm
not sure if non stored would work
🫢 1
we had a problem where when the PDF was generated as a result of sending an email and ticking
Include Transaction
then the UE doesn’t fire.
so we actually regenerate the JSON for the text field on each save of the parent record.
the OTHER way you could do it is that you can actually
<#include>
the output of a Suitelet….
m
Would it look like: vendor bill new field:
itemJson
(JSON blob of record.toJSON().sublists.items essentially- stored but non-visible) on invoice pdf -
record.customVendorBill.itemJSON
?
j
you’d need the JSON on the main record
m
UE meaning user event or user event script? Sorry I'm unclear what roll that plays
j
User Event Script
I thought “oh I’ll just fire a UE script on beforeLoad in Print context, and generate the text into my non-stored field” but it doesn’t fire when attaching PDF in email
if that’s never something you do, though, that method could work for you
might have been a workflow action and not a UserEvent, I can’t honestly remember now as it was several years ago that I last tried
m
Hmm... a second thought was also if I could create a button on the invoice record that essentially pulls the print of a vendor bill (so I could access all the sublist values on the bill and then just pull the relevant invoice fields via record.referenceToInvoice.tranid etc)
But sorry another clarifying question jen... with your solution it would be a stored field on the vendor bill record that's populated via a user event script? Could it just be a sourced (and stored) field instead of needing the UE to populate it? I don't need to worry about the vendor bill unsyncing from the invoice, I have a UE script that updates the invoice everytime the vendor bill is modified (I guess I could also just populate the json field from that then too huh...)
j
Yeah if you can source it you could do that. Our use case was a bit more complex and had to do a bunch of a logic to get JSON object that had a bunch of other info in it that the PDF used.
m
Okay thanks for all the help Jen and David, will work on this a bit