Generative AI Proposed This for a ZPL Template, Can I Replace Values with Variable, Table Field, and Aggregation values?

My company GenAI tool proposed the following approach to update label content - I’m wondering if we can accomplish this without custom widgets, just with trigger functions, to replace the field placeholders with Variable, Table Field, and Aggregation values:

zpl_template = open(“label_template.zpl”).read()
zpl_filled = zpl_template\
.replace(“{{SORT_ID}}”, “123”)\
.replace(“{{SORT_ROW}}”, “B12”)\
.replace(“{{PRIORITY}}”, “High”)\
.replace(“{{LPN}}”, “ABC123456”)\
.replace(“{{FACILITY_NAME}}”, “Bridgewater Value Added Service Center”)\
.replace(“{{PO_NUMBER}}”, “PO987654”)\
.replace(“{{DATE}}”, “30-JAN-2026”)\
.replace(“{{SET_NAME}}”, “Widget Parts Bundle 3”

Hi,

This should be possible - you just need to ensure that all the variables being used are either text or converted to text within the expression editor.

Try using this ZPL Viewer Unit Test - ZPL Viewer Widget Unit Test to play around with your ZPL template/variables and check if your label is being generated correctly. It will convert the ZPL into a viewable label :slight_smile:

Hope this helps, let me know if I have misunderstood your requirements!

Kind regards,

Suraj Patel
Bow&Stern IT Professional Services

What would actually run the above substitution logic to populate the template before sending the populated template content to the printer via device trigger? Would this need to be a custom widget, a connector function, or could I do it in a trigger (e.g. text substitute functions)?

Ah I think I understand better now. I’ll list out the steps here:

  1. Have the ZPL code for the label

  2. Ensure there is a variable within Tulip for each field to be updated

  3. Write trigger logic to store an expression to a ZPL Code variable, inserting Tulip variables or record placeholder fields into the ZPL code. This logic should only be executed after all variables have been populated with their final values. I have included an example here:

Here is a snippet of the expression in plain text vs the original ZPL here:

Original:
MATERIALPLACEHOLDER‘^FS^FT15,90^A0N,19,20^FH^CI28^FDMaterial:^FS^CI27^BY1,3,76^FT15,319^BCN,Y,N^FH^FD>:’QUANTITYPLACEHOLDER‘^FS^FT15,234^A0N,19,20^FH^CI28^FDQuantity:^FS^CI27^BY1,3,82^FT231,177^BCN,Y,N^FH^FD>:’ +

In Expression Editor:
@Variable.MATERIALVariable.MATERIALVariable.MATERIALVariable.MATERIAL + ‘^FS^FT15,90^A0N,19,20^FH^CI28^FDMaterial:^FS^CI27^BY1,3,76^FT15,319^BCN,Y,N^F@Variable.QuantityVariable.Quantity^FD>:’ + TOTEXT(@Variable.Quantity**)** + ‘^FS^FT15,234^A0N,19,20^FH^CI28^FDQuantity:^FS^CI27^BY1,3,82^FT231,177^BCN,Y,N^FH^FD>:’ +

For example, you would replace {{FACILITY_NAME}} in your ZPL co@variable@variable.FacilityNameFacilityName@Table within the@Tableexpression with:

  • @variable.FacilityName +

OR

  • @Table Record.DetailsRecordPlaceholder.FacilityName +

If the ZPL code does not already have placeholders to highlight where the dynamic fields should be, you will probably need to request for these to be added or ask for a label with all values filled as “XXXXXXX” to make it easier to see where you will need to insert the Tulip variables.

  1. Create a trigger to send the ZPL code to the printer - I usually do this on a “Print” button:

The ZPL viewer unit test I shared is the best place to test your expression to ensure it is populating correctly without needing to print the labels directly.

Does this all make sense? Let me know if you have any questions!

Sorry for the mistake here, it should look like this:

In Expression Editor:
@Variable.MATERIAL + ‘^FS^FT15,90^A0N,19,20^FH^CI28^FDMaterial:^FS^CI27^BY1,3,76^FT15,319^BCN,Y,N^F@Variable.QuantityVariable.Quantity^FD>:’ + TOTEXT(@Variable.Quantity**)** + ‘^FS^FT15,234^A0N,19,20^FH^CI28^FDQuantity:^FS^CI27^BY1,3,82^FT231,177^BCN,Y,N^FH^FD>:’ +