How to use the token data in the email templates to form the email body content?

How to use the token data in the email templates to form the email body content? Token data is created from the objects.
1 answers

Tokens can be a little difficult. In the email template you probably would like to dynamicly add text to the mail. This way you could use Dear, {%UserName%} and the text would be dynamicly adjusted with each username. The problem with tokens is that you can only retrieve data one deep of the object that is attached to the template. In the above case I would attach the user object (containing the UserName data) so the token can be replaced by the real value.

Now lets say I also want to have a token about the order of this user. If I have a path from User to Order I can use the reference to Order. But if I would need a reference deeper from Order to the objects in the order I could not retrieve those. It would then make sence to attach the order object to the template because then both the user and the objects in the order can be retrieved.

What I do in most of my projects is create one print entity and attach all objects I would like to use in my templates. This way you always attach one object to the templates and from there I could always 1 deep retrieve all the objects I need in the template.

Now how to change the tokens? Take a look at the mail module microflow IVK_CreateAndSendEmail. This microflow retrieves the tokenlist from the template. The java action needs this list to change the tokens and needs the object of the correct type. Do not give a user object if the template uses a order object to fill out all the tokens. You need to make sure that all is correct for you hand the data to this java action. If all is allright you will receive the text back where all the tokens are replaced with real data from the object.

Hope this helps.