Some interesting support questions to help you customize your EvolutivoFW application.

How can I create a business action with a user confirmation?

Create a business action record and set the Link URL to

javascript:userConfirmAction('runBAWorkflow', [131, $RECORD$])

Inside the function userConfirmAction, you should put the function that you want to call.

The Confirmation Alert field should be set to yes and the Confirmation Message field should contain the text you want to show to the users.

Business Action with confirmation

I need to send an email once every two years, a "Two Year Reminder" email, to my contacts.

I am assuming some sort of "last interaction date" so that each contact will receive this email on different days depending on when they last interacted with the company. If your business logic is not that, read on anyway, it is an interesting use case.

Solution

Sending an email on some event is clearly a workflow. Since the event that triggers the workflow is time-based, we are talking about a Scheduled Time-Based Workflow. Of the different types of scheduled workflows, we are looking for the Daily one because we want to check once a day (daily) for all contacts to which we have to send an email.

The condition requires us to know when was the last interaction date so we can calculate if two years have gone by. So we add a custom date field in the Contacts module that holds the last interaction date, we add a condition on the scheduled workflow to retrieve the contacts that are two years old each day and do any tasks we need; send an email, update the last interaction date, any other task we need to do.

This is the screen in Layout Editor to add the new date field:

Adding a custom date field to Contacts

What does it look like?

The workflow is set to run every day at 6:00 AM. Without conditions, it would process all existing contacts and look like this:

Scheduled daily workflow for Contacts

I suppose there are various ways of setting the conditions we need. I decided to add the "last interaction date" custom field and calculate the distance between that date and today to be two years. That can be done by subtracting approximately two years from today and comparing it with the last interaction date:

lastinteractiondate is sub_days(get_date('now'), 2 * 365)

two years ago

Which generates this SQL to retrieve Contacts to work with:

SELECT vtiger_contactdetails.contactid
FROM vtiger_contactdetails
INNER JOIN vtiger_crmentity ON vtiger_contactdetails.contactid = vtiger_crmentity.crmid
INNER JOIN vtiger_contactscf ON vtiger_contactdetails.contactid = vtiger_contactscf.contactid
WHERE vtiger_crmentity.deleted=0 AND ((( vtiger_contactscf.lastinteractiondate = SUBDATE(CURDATE(),(2*365)) )))

Note that you can use the HelperScripts evalwf.php script to see that SQL.

Now we add the tasks which are a "Send email" task and an "Update field" task to set the lastinteractiondate to "today" for the next two year iteration.

Update field workflow task

Another way of selecting the contacts from two years ago is using the special scheduled workflow operators. As described in the Scheduled Time based Workflows documentation, we have a set of special date field operators for these types of workflows. For our case, we can use the "More Than X days ago" operator to trigger the workflow. The condition looks like this:

more than x days

Which generates this SQL that should return a similar set of contacts:

SELECT vtiger_contactdetails.contactid
FROM vtiger_contactdetails
INNER JOIN vtiger_crmentity ON vtiger_contactdetails.contactid = vtiger_crmentity.crmid
INNER JOIN vtiger_contactscf ON vtiger_contactdetails.contactid = vtiger_contactscf.contactid
WHERE vtiger_crmentity.deleted=0 AND ((( vtiger_contactscf.lastinteractiondate < '2022-11-21' )))
Variations

This type of request has many variations and the workflow trigger options make it very flexible to implement many types of automated process solutions. You can read about two of them in the Weekend Warnings with Workflows and Scheduled Workflows coreBOS blog posts.

References

Powerful stuff!! HTH!

Photo by Neil Thomas on Unsplash

Previous Post Next Post