If I have an items sublist and a custom field whic...
# advancedpdf
n
If I have an items sublist and a custom field which is populated as an array and I want the n-th value of my custom field value based on the n-th index of my item sublist is this possible? If so could someone post the syntax please? so I'm saying as I iterate items can I do: my_custom_field_as_an_array[item?index].some_key
d
I'm not sure I understand. Is your custom field a string representation of an array containing objects? Like:
Copy code
[
	{some_key:some_value, some_other_key:value},
	{some_key:some_value, some_other_key:value},
	{some_key:some_value, some_other_key:value}
]
if NS ever updates the freemarker version you could use ?eval_json, but you'd be forced to use ?eval for now (which comes with the warning _not_ to use it on JSON) if it was just a string representation of an array, you could get away with ?split
n
@David B Thanks for replying, I've been off Slack for a while and did not see your reply. Essentially I am iterating the items sublist. Some data I need in that sublist is not available and so I've added it to a custpage_ field using a UE script. The data in that field is an array of JSON, much as you described. What I wanted to do, and actually succeeded in doing 🙂 was, on iterating the item sublist, for a specific column on each row, pull in the corresponding custom field array value by index. So I'm on line 0 of the item data for the column "My Custom Value" I want the mydata[item_index].my_custom_data_value. I ensured the data order was the same, by sorting both my UE script search results, and the items list in freemarker.
d
that's brilliant to hear, thanks for taking the time to respond. Actually glad to hear the resolution, I was interested in what you were doing. Out of curiosity, what kind of information does the custpage_ field hold? is it some kind of validation of the items sublist; a record of the item sublist previous values?
n
The script runs on an "Invoice Group" and my script help says 'Gathers up the SO tranid for each of the included invoices "createdfrom" field.' Which is just as well as I couldn't recall 😄 So yeah, for each Invoice on the Invoice Group transaction I needed the tranid. (kinda confusing me talking about item lines, just trying to keep it "familiar" 🙂 )
The sublist looks like this and we could find no way to add the column field via the UI.
The Print Output now includes the tranid: (So number)
...yes that made me look twice too, but the relationship between invoice number and SO number is as shown above, I've not borked it 🙂
d
aha, that is interesting. not currently using invoice groups, but will tuck this info away if/when I do 👋