Skip to main content

11.1 SDK Field Action

This type of function is normally used to enhance the fields of a record, dynamic form, etc. with values ​​calculated using the following method:

SDK::setProcessMakerFieldAction($func, $src, $label, $parameters='');
$func : function name
$src : file path containing the function
$label : function label
$parameters (optional) : static parameters (e.g. fixed field reference)

To unregister the file use:

SDK::unsetProcessMakerFieldAction($func);
$func: function name

These functions can be called from the appropriate “SDK Functions” sections available in the “Option Selection” drop-down menu located at the top right of each individual field.

N.B: All registered custom functions will always be inserted in the “SDK Functions” section, the “Date Functions” section is used exclusively to contain the php functions available as standard that concern the date fields.

image.png

image.png



A concrete example of an SDK function of this type is the “sum()” function that returns the sum of the parameters (static or dynamic) passed.
It is possible to store the result in a field of a dynamic form of a Process helper by inserting the function as a default value, or insert it directly into a field of a form using the standard actions of create or update entity.


image.png


image.png

Example

I am recording a function to calculate the percentage that will need the input parameters percentage and total.

SDK::setProcessMakerFieldAction('vte_calculate_percentage','modules/SDK/src/ProcessMaker/Utils.php','Calculate percentage (percentage,total)');

In the implemented function I will then indicate the 2 parameters and return the result of the operation.

function vte_calculate_percentage($percentage, $total) {
    global $engine, $current_process_actionid;
  
	$value = ($percentage / 100) * $total;
	return $value;
}

N.B.  Inside the registered functions, the global variables $engine and $current_process_actionid are available.
These respectively contain the object containing all the information relating to the process being executed and the id of the current action (e.g. Create entity, Update entity, ...)