Getting Custom Field in Order record for Email Template

Jeff Torririt asked on January 31, 2019 02:21

Hi there,

I'm modifying our order notification to customer email template to include a custom field defined in our Order record.

I tried {% Order.GetValue(columnname, "") %} but it returns an empty or null value even though there's a value in that custom field. Do I need to setup something in the Order record?

Thank you

Correct Answer

Eric Dugre answered on February 5, 2019 14:09

Jeff,

During the checkout process, the order is not created- it is only created after the final step of the process. At this point, you are only working with the shopping cart (ECommerceContext.CurrentShoppingCart) and you can only work with fields of that object. Fortunately, there are two helpful mechanics that you can use to accomplish what you're looking for.

Firstly, there is a pre-defined ShoppingCartCustomData field that you can use to add custom data to carts, and this data is automatically transferred to OrderCustomData when the order is created. You can add items to this field by referencing a key like a Dictionary: ShoppingCartCustomData["MyField"] = 123.

If you don't want to use that field and really want a dedicated custom field for your data, you can create the field in both ShoppingCartInfo and OrderInfo. If you name the field exactly the same, the data from the cart will be transferred to the order, just as above with ShoppingCartCustomData. So, you need to create 2 fields named "MyField" (for example).

All this said, the best way to modify the cart data during checkout is using a custom web part- I'm not sure what your data is and where it comes from, but generally some user-interaction is required (e.g. a form) and the web part takes the input and saves it to ECommerceContext.CurrentShoppingCart.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Jeff Torririt answered on February 5, 2019 01:53

So I found out that the reason my custom field is not being included in the email is because the email is being sent after the order is created and the custom field is being set after the email was sent.

My script updates the existing order to include the custom field. Is there a way to set my custom field during checkout process before the order is submitted and saved?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.