retailCRM Documentation

Rules of trigger preparation

Expressions in filter and condition of triggers are set in definite syntax and should return logical result.

In expressions you may work with objects, which is transmitted in event. The list of available methods in objects you may see in reference book of objects.

In triggers on event «Order change» and «Customer change» there is available object changeSet (type Change\EntityChangeSet). In that object there are changes made in the order/customer at the moment, and these changes are transmitted in trigger. In reference book of objects you may see available methods of this object. Read more about changes set you may in relevant article.

Expression examples

1. Check if the order has delivery type "Russian Post":

order.getDeliveryType() and order.getDeliveryType().getCode() == "russian-post"

2. Check if the delivery status field has been changed

changeSet.hasChangedField("integration_delivery_data.status")

3. Check if the order status has been changed to "Did not get through"

changeSet.hasChangedField("status") and changeSet.getNewValue("status").getCode() == "did-not-get-through"

4. Check if the order status group has been changed to "Complete" or "Cancel"

changeSet.hasChangedField("status") and changeSet.getNewValue("status").getGroupCode() in ["complete", "cancel"]

5. Check if the order is expired

changeSet.hasChangedField("expired") and changeSet.getNewValue("expired")

6. Check if the phone in order is specified

order.getAnyPhone() != ""

7. Check if the customer has not unsubscribed from mailing

not order.getCustomer().getEmailMarketingUnsubscribedAt()

8. Coming of new order

changeSet.isCreate()

Checking of the last trigger run

Using function last_run it is possible to get information on the last trigger run. Function returns an object type RuleExecution or null, if trigger has not been run yet. With that the last run is returned for the context of current events, for example for event "Order change" will be returned information on the last run of trigger for order editable at the moment.

The function takes 3 arguments, they are all optional:

For example, run trigger not more than once per day:

not last_run("1 day")

For example. check the trigger run by code:

last_run(null, "send-email-1day")

For example, conditions for trigger on event "Order change", which runs if the customer paid already the 2nd order for week

changeSet.hasChangedField("payment_status") and changeSet.getChangedField("payment_status").isPaymentComplete() and
last_run("7 days", "order_pay", order.getCustomer())

Action on data change in order, customer, manager

Using these action you may change information on order, customer or manager when trigger runs.

For example, when order on amount of 1000 euro has been paid, the mark "VIP" should be set to the customer:

Expression has the same syntax with trigger condition, but as its result should be relevant value for the field, i.e. for field Surname it should be string, for custom field of date type it should be object DateTime, for Store it should be object of class Site, for custom field of list type it should be relevant element.

For this matter in expressions for specifying of reference book data you may just specify its code (see below), also it is possible to use functions.

For using in expressions there are the same objects available like for trigger condition, for example order, customer, changeSet

Automatic code conversion in the reference book element
Specifying of date

Features of segment triggers

The fact when customer gets in the segment and the fact when customer gets out from segment are recorded to customer history, and that means these events can be catched by triggers.

Example of trigger condition for finding out if the customer get in the definite segment:

changeSet.hasChangedField('segments') and changeSet.getNewValue('segments') and changeSet.getNewValue('segments').getCode() == 'some-segment'

Example of trigger condition for finding out if the customer get out the definite segment:

changeSet.hasChangedField('segments') and changeSet.getOlValue('segments') and changeSet.getOldValue('segments').getCode() == 'some-segment'

Triggers on the missed calls

In triggers on the missed calls there are an object Call. Description of available methods you may see in reference book of objects. The call may have definite user, to whom the call was made call.getManager(), the order, call is linked with call.getOrder(), and customer, who called call.getCustomer(). Manager, order and customer can be not specified, and it is necessary to check previously if these objects are used in trigger condition.

When creating triggers on the missed calls you may not specify filter and trigger condition. This way trigger will run on all missed calls. But there can be situations when it is necessary to process only definite categories of missed calls. There are examples of conditions for some categories below.

Call missed by user with email john@smith.com:

call.getManager() and call.getManager().getEmailAddress() == "john@smith.com"

Call missed by user from group Managers:

call.getManager() and call.getManager().isManager()

Call missed by users from group with symbolic code call-center:

call.getManager() and call.getManager().hasGroup("call-center")

Missed call from VIP-customer:

call.getCustomer() and call.getCustomer().getVip() == true

Missed call from customer with total orders amount more than 300 euro:

call.getCustomer() and call.getCustomer().getTotalSumm() >= 300

Missed call on the order with status "New":

call.getOrder() and call.getOrder().getStatus().getCode() == "new"

PrintEditHistory
Page last modified on January 22, 2018, at 10:07 AM