Custom Ticket Order Field Data in HTML Templates?

Hello!

We are hoping to display data from a custom order field on our HTML templates that we send out as invoices. Does anyone have tips or knowledge on how to reference custom order data in the HTML template module?

Thank you!

  • ,

    This should not be too difficult of an issue to resolve for you.  If we assume that you are starting by looking at the standard (V15) sample that Tessitura provides called "Example Order Confirmation", this should be a simple guide to getting that template to show the custom data.  Now, obviously you will need to do more playing around to get it to eventually look the way you want it to in the end, but this should at least get you the data and able to play around with it.

    In the beginning section where you see all the "var" declarations, insert a new line to become your new line 29 as indicated below (pushing the end brace down to 30).

    var hasCustomData = Model.OrderProductView.CustomDataItems != null && Model.OrderProductView.CustomDataItems.Count > 0;

    Then, in line 37/38 (depending on how you look at it before/after inserting the code above, insert the following code:

    @if (hasCustomData)
    {
        var customData = Model.OrderProductView.CustomDataItems;
        foreach (var custom in customData)
        {
            <p>@custom.Name</p>
            <p>@custom.Index</p>
            <p>@custom.KeywordId</p>
            <p>@custom.IsDropdown</p>
            <p>@custom.Value</p>
            <p>@custom.DataType</p>
            <p>@custom.Description</p>
            <p>@custom.EditIndicator</p>
        }
    }
    
    

    That is an extremely basic sample of code and likely not going to be what you want for your final product, but it is at least the core example of what you need to do to cycle through all of your custom data points (assuming you have more than one), and then all the potential values for you to then include in your final HTML Template output.  Presumably a number of them are irrelevant to the customer (e.g. DataType), but that at least is the full list of options "out of the box", as it were.

    Best of luck!

    John A. Moskal II

  • Hi John,

    Thank you so much! We are currently in V16, but I'll give this a try and report back.

    Lauren

  • John, this still works great in V16! I am hoping to use my variables to directly affect my Total Due Amount, and the local variables can't be used outside of the above code. Do you have any advice?

    Thank you so much for this head start!

    Lauren

  • ,

    The thing to which you are falling victim (I assume without seeing the error message) is what is called "variable scope".  I assume that the error message that you are getting is something like "The name [Variable Name] does not exist in the current context" when you try to place it elsewhere.  This is something that takes a little bit of trial and error to truly get a grasp on how exactly it works, when you will see that error, and when you will not when trying to reuse a variable from above further down below.  That was partially my fault for basically giving you a sample that had limited scope to it.  (I am still not sure that I could 100% write out an instruction manual as to how it works, but I can nevertheless make it work well enough when I need to do so.)

    The sort of "safest bet" to ensuring a variable scope that you can use all over your HTML template is to declare it in the very first @{ } block.  If you know what type of variable it is, that is easy enough "int sampleVar = 0" or even "var sampleVar = 0".  If you do not, you will have to figure out a way to gimmick it into adopting the proper form because the syntax will not allow you to just declare a variable without a type.  So "var sampleVarTwo;" will also return an error because it has no idea what type of variable "sampleVarTwo" is supposed to be.

    It does slightly depend on what you are trying to do.  If you know your custom field is a money field (as it sounds like it might be if you are trying to use it to add to the "Total Due Amount"), you could just state in the opening block something like "decimal customData = 0;".  Then, later on when you are cycling through your custom objects, if you only have one, then it is easy enough to just set that variable equal to that field, so "customData = custom.Value;", but if not, then you might need some form of if/then or else a known index X, e.g. "custom[X].Value", in order to apply that correctly.  Then you would just reference later in your code "totalDueAmt = totalDueAmt + customData".

    Hopefully that helps.  Worst case scenario, feel free to send me what you are looking at, and I can glance at it and see what I see.  But this sounds like it should be a relatively easy add for you, and I hope it works well!  (Also, do not forget to account for potential null data.)

    John A. Moskal II

  • Hi John,

    Thank you so much! This has been a ride for me, and you have made it much smoother with your advice. I ended up declaring a couple new variables that worked for me. I tried to make the value a decimal in the setup of my custom data field originally and it wouldn't stay a decimal once it hit my HTML Template. My math now works perfectly!

    var hasGF = Model.OrderProductView.CustomDataItems[1].Value != null;
    var hasSchol = Model.OrderProductView.CustomDataItems[0].Value != null;
    //later in the code//
    var scholOut = decimal.Parse(Model.OrderProductView.CustomDataItems[0].Value);
    var gfOut = decimal.Parse(Model.OrderProductView.CustomDataItems[1].Value);

    Gratefully,

    Lauren Staples