Field functions

This article explains how to create field functions and use them in your touchpoints.

Christiaan Proper avatar
Written by Christiaan Proper
Updated over a week ago

To create field functions, head over to

When creating a new field function, make sure to give it a descriptive name without no-break spaces.

In the code editor, you can create functions with vanilla Javascript.

The best way to explain how you need to use it, is with an example case. The case below is with two visitors, one is a b2c visitor, the other one is a b2b visitor.

Two different visitors:

customertype: b2c

customertype: b2b

Both see the following two products recommended to them:

Product 1:
name: Headset
price: 100
b2bdiscountperc: 20

Product 2:
name: Microphone
price: 50
b2bdiscountperc: 50

The recommendation is shown by a Datatrics touchpoint, it has the following HTML code:


    {{#each items}} itemcount='2'
        € {{#fieldfunction discountfunction itemname=name price=price discount=b2bdiscountperc}}</li>

The code above contains the helper #fieldfunction, here it is without the other code:

{{#fieldfunction discountfunction itemname=name price=price discount=b2bdiscountperc}}

Field function:

The field function itself has the following JavaScript code (same code as the screenshot above):

if (data.profile.customertype == 'b2b') {
    output(data.price * ((100 - / 100));
} else {

Based on the profile field “customertype”, both visitors get a different output:

Output for consumer:

  • Headset

  • Microphone

Output for business:

  • Headset

  • Microphone

// End of the example

How to use in your template:

{{#fieldfunction discountfunction fieldfunctiondataname=brand}}

Content item that has a field called “brand” with the value “Nike”:

name: Cool Shoe
price: 150
brand: Nike

How to use it in field functions:


(it contains Nike for the example above)

You can use all content item fields to send along with the #fieldfunction helper to use in your field function, example:

{{#fieldfunction discountfunction itemname=name price=price specialprice=special_price itembrand=brand}}

You can also use all profile fields in the JavaScript of your field function, example:

if ( == 'Christiaan Proper') {
    output(data.price * 0.5);
} else {
Did this answer your question?