Home  >   Articles   >  Set up a Workflow Action to Invoke Custom Function
Articles in this section

Set up a Workflow Action to Invoke Custom Function

The Workflows module provides you with a simple interface to add custom actions that execute on saving an entity.
R
Ruba
29 Dec, 2023 - Updated 3 months ago
Table of Contents

Invoke Custom Function - A Workflow Action

The Workflows module provides you with a simple interface to add custom actions that execute on saving an entity.

Vtiger has a Custom Task function of entity method tasks that calls certain methods on Vtiger entity objects. Custom Tasks provides a way for developers to add custom actions to workflows. Let us walk through creating a Custom Task.

For example, if you want to compute a natural Math Log as a custom operation, then first, we need to register a method that will perform the operation. The method needs an operation name, a file path (can be anywhere, even in a custom module), and a function name.

Let’s say you have a custom module called Deals. You can register a method in the post-install event(vtlib_handler API of Deals.php file) of the module. The event is triggered after the module is installed. 

For more details on how to write a module, click here.

 

Note: We have taken the example of the Deals module only for better understanding. Deals is a default Vtiger module and is available in the Sales and All-in-one editions. To learn about Deals, click here.

 
 
 

Setting up the workflow

Follow these steps to set up the workflow with a custom function:

Accessing the workflow page:

  1. Click the User Menu on the top right corner of the screen
  2. Click the Settings button
  3. Look for the Automation section
  4. Select Workflows
  5. Click the +New Workflow button
  6. Select Standard

Entering the basic information:

  1. Select the Target Module 
  2. Enter workflow name, status, etc

Select the workflow trigger:

  1. Select the Workflow Trigger

Set up the workflow entry criteria:

  1. Click the +Add Condition button
  2. Enter the condition that must be satisfied for the workflow to execute.

Note: To learn about the basic information, trigger, and entry criteria, click here.

Set up the action:

  1. Click the Add Action drop-down
  2. Select Invoke Custom Function
    • This opens a window where you must enter the Action Title
  3. Enter the Action Title
  4. Click Save to save the action
  5. Click Save to save the workflow
Note: If you want to update the Purchase cost of Products based on the List price given for the Product in the latest Purchase Order, do the following:
  • The admin has to select the custom function when creating a workflow for PO,
  • The custom function will update the Item's Purchase Cost based on the following formula:
    • ((Qty*List price)-Item level discount)/ Qty
  • This should update the Purchase cost for all the Items selected in the PO/Bill.
  • The latest selected price is recorded if the same product is selected in the PO or Bill more than once.
    • For example, if the product - Glass is selected in the 3rd and 7th fields with prices of 400 and 600, respectively, then the price of the 7th field, that is 600, is recorded.
  • Ensure that the ModTracker entry should be added to the Product and the Product or service workflow should not be triggered.
Was this article helpful?
0  out of  5  found this helpful.
Comments 0
Be the first to comment
© Copyright 2023 Vtiger. All rights reserved.