Blog Posts Process Management

Useful scripts

Blog: Flokzu

In the process form you can define a script field (one of the functions available under calculated field) to write your own validation scripts and calculations in Flokzu.

This post puts together some useful scripts and explains how they work.

 

Performing arithmetic operations

Since the scripting engine is JavaScript, some adjustments need to be done to perform certain operations. Given two fields A and B, you can add them up using the JavaScript function ‘parseInt’ like this:

parseInt( {{A}} ) + parseInt( {{B}} )

Thus we make sure that the engine will interpret the value of fields A and B as numbers.

 

Limit number of decimal places

When working with decimal numbers, the result may contain an infinite number of decimal places. To avoid this, we can modify the function and limit the number of decimal places to a certain number (in this case 3):

( {{A}} * {{B}} ).toFixed(3)

 

 

Difference in days between two dates

Given two date fields ‘Date A’ and ‘Date B’, the difference in days is solved by this script:

Math.ceil(  Math.abs(new Date( {{Date A}} ).getTime() – new Date( {{Date B}} ).getTime()) / (1000 * 3600 * 24));

No matter which date is greater, the difference in days between the values entered will always be correctly calculated.

 

Showing error messages

In some cases it is necessary to do some type of validation and if it is not fulfilled, to show an error message to the user. This is possible using a script.

Example: Compare if two fields A and B are equal and if they are not, display an error message.

if( {{Field A}} != {{Field B}}) { alert(‘Values don’t match!’); }

Using JavaScript

The type of validations that can be done using a script field is limited. Logical functions such as if, for, case, or variables cannot be used.

A solution to overcoming this limitation is to allow JavaScript to be used. For that you have to start the script with 0; (zero followed by a semicolon) and use the variable newValue to display what you want in that field.

For example:

0;
var CONS = 10;
if ( {{Combo}} == ‘TEST’ ){ newValue = 20 + CONS; }else{ newValue = 30 + CONS; }

If the value of Combo is TEST, the field will display the value 30, otherwise 40.

The post Useful scripts appeared first on Flokzu.

Leave a Comment

Get the BPI Web Feed

Using the HTML code below, you can display this Business Process Incubator page content with the current filter and sorting inside your web site for FREE.

Copy/Paste this code in your website html code:

<iframe src="https://www.businessprocessincubator.com/content/useful-scripts/?feed=html" frameborder="0" scrolling="auto" width="100%" height="700">

Customizing your BPI Web Feed

You can click on the Get the BPI Web Feed link on any of our page to create the best possible feed for your site. Here are a few tips to customize your BPI Web Feed.

Customizing the Content Filter
On any page, you can add filter criteria using the MORE FILTERS interface:

Customizing the Content Filter

Customizing the Content Sorting
Clicking on the sorting options will also change the way your BPI Web Feed will be ordered on your site:

Get the BPI Web Feed

Some integration examples

BPMN.org

XPDL.org

×