Hi All,
I have an issue where I need to display a barcode in a dynamic table on the page. The data is coming from a nested table in the datamapper.
The fields listed in the table should show the first item in the first table follow by the first item in the nested table, then the second item in the nested table. The barcode will be the items from the nested table.
The attached template is created in version 2022.2. I created a dynamic table using the Insert Dynamic Table wizard. The first row repeats over the ‘detail’ table where the send row repeats over ‘detail.data’.
I the example I use expressions for regular data (introduced in 2022.2, although this doesn’t really matter for the example). Next I inserted an inline barcode in the table cell (the selected data field is not important at this stage), assigned the barcode element a class via the Attributes panel (‘barcode’) and made the appropriate settings via the Barcode Properties dialog (right click the barcode object).
Subsequently I changed barcode script so it sets the content of the barcode element to the text of the respective data row. First I changed the selector of the script to ‘.barcode’, expanded the script and deleted the code.
When iterating over items in a detail table your script has access to the detail record used for that row. This information is accessed via the ‘this’ object. For convenience sake I changed the scope of the script to “each matched element” (so the scripts iterates automatically over all .barcode elements). This allows you to work directly on the matched element and the accompany data as shown in the image below.
With this setup there is no need to create ‘for loops’ etc. Rows are repeated by the dynamic table logic and as mentioned they are ‘aware’ of the record/detail record used to render this row.
Thank you Erik, That works perfectly. It has raised a secondary issue though. If there are 3 items or less then I need to show the barcode. If there are any more than that I should not show any barcodes. Is there a way to accomplish that?
Sorry, should have thought of that when first posting.
The rows you have numbers in will be shown but not counted towards a total. If there are more than 3 of the other rows, in total, then it will not show any barcodes. If there are 3 or less of the other rows then each will have a barcode. In your example there would not be any barcodes.
The quickest I could come up with is loading a snippet with a simplified table (no barcode rows) and replace the base table when there are more than 3 detail rows.
Thanks for helping with this. I’ve attached a datamapper file to try to explain things better. The first record contains a total of three items in the detail table (in the nested ‘code’ table) and this should show barcode. The second record has four items in the detail table (again in the nested table) and should not show the barcodes. It’s based on the total number of items and not the length of a table.
Thanks that was helpful. Attached a new version of the template. I’ve used the same technique as the previous template but changed the logic to determine when to load the snippet. The scripts iterates over the detail data and accumulates the number of nested ‘code’ levels.