Advanced Tutorial: Automatic Delivery Charge Based on Distance via Google Maps

Hi Team,

can you point me to right direction I’ have followed the tutorial and managed to impalement Automatic Delivery charge. I’m having minor issue with the Show message action, basically the distance message only appears when product is added to the ticket. I have missed something in the rules and can not pinpoint (I’m still learning).

No distance message displayed

Distance message only appears when adding a product,

Rules:

A quick look at the Tutorial indicates that the Entity Data and Distance is set when the Event for Order Added to Ticket is triggered, so it is operating as designed.

You could possibly change that Rule to fire on the Event of Entity Selected and/or Ticket Entity Changed, however, since the Delivery Charge is based on a Percentage of the Ticket Total, it would not know how to calculate that when no Orders are on the Ticket.

So instead of chaning the Rule, maybe just add another Rule or Rules for Entity Selected and/or Ticket Entity Changed and fire the Show Message action in those Rules to display the Distance.


BEFORE YOU DO THAT … I see you have 2 Actions in your Rule which you named Delivery Message and Delivery Charge. What do they do? Show the Action for Delivery Message. You need to use a [:variable] in that Action for the parameter so you can feed a value into the Action from the Rule. Like this:

Here are the two actions.
Delivery Message Action displays the distance and Delivery Charge calculates 10% from the ticket amount.

You cannot do that. The Action (Show Message) cannot directly retrieve the value you have supplied. You need to supply the value from the Rule. So you must use a [:variable] in the Action “Message” Parameter and then feed the values into the Action from the Rules as I have shown in my previous post.

You will need to remove the Action from the Rule, then Save the Rule, then open the Rule and add the Action back in. Then supply your calculated value expression to the Action via the Rule.

I have changed to following and the behaviour is same. So the calculated value expression to the Action via the Rule need to be corrected.

Then supply your calculated value expression to the Action via the Rule.

can you show how to calculate the value expression for following example.

10% of ticket total
Fixed price of £5 to all deliveries

Thank you

Update:

I have managed to find the solution/work around using shell subtitle feature using below tutorial as an example.

1.Created an “Update Application Subtitle” action (header Distance)
2.Created a second “Update Application Subtitle” action (clear Ticket header)
3…Created a “calculated distance” rule (Header Distance)
4. Created a “Ticket Closed” rule (Clear Ticket Header)

Header Distance - Event Name set to Ticket Displayed

Delivery Orders Distance Rule - set the Event Name to Ticket Created

Now when Ticket is opened calculated Distance is always displayed.

I have identified an error with one of the rule. happy with the solution/workaround. Thanks…

my distance calculation is not working can you help

thanks

Sure what do you want help with?

Trying to implement this, and this does work with ‘Order Added to Ticket’ event and updates the distance field.

Having trouble trying to get this rule to fire when ‘Ticket Entity Changed’, as checking after every order item is going to flood google with API requests.

Or is there a way to get the distance field to populate on the ‘new customer’ screen?

Can I call the script here?

Many Thanks

You can get distance just about any time you wish. It can even be stored meaning it only checks it once.

Hi @Jesse I have edited my post to show a screenshot; can i call the script in the entity custom field?

You probably would not want to do that. Anytime it would read that field it would run the script. It would be better to run it once and store it then feed the stored value in the Custom Data Field.

You can do that with Entity Updated event maybe? Execute an update program setting and store it in the database.

I understand, I will have a play about - its trying to find an event that the rule can use that is well before order added to ticket - I’ll keep trying! Thanks

Entity Updated doesn’t seem to work

Yes you need an event that is not repetitive a single time event. THen store the result in a program setting and you can reference that program setting so it doesnt have to run the API every singe time. You could also store it as a task.

Try the ticket entity changed event but use that event to update a program setting instead of the entity itself. Use the program setting in the Custom Data Field.

I have no idea :weary: I’ll have a break and come back to it with fresh eyes later, just frustrating that the script is working but is not updating the entity when I need it to

I can help you with it later tonight if your still needing help. I have to go out of town now and wont have access to a system.

1 Like

Sorry if I’m missing something but since your already using a script on postcode can’t you add to that script and map the value?

1 Like

@JTRTech i did think this could have been an option and is probably what I need to use (so that Distance could be mapped then as $5, at same time as street name etc) I have attempted to do this a couple of times but I’m not up to speed with scripting so struggling to pull the distance data.

You already have both scrips so should be easy.
Add distance script as another function and call that function from postcode lookup script as your distance in return.
Paste scripts.