This article is also available in:
Data Validation

Validate an identity card's numbers

Some countries implement algorithms for validating identity document numbers. These algorithms can be reproduced in Javascript:
function validateId(){
var ID = Flokzu.getFieldValue( [[Id Number]] ); 
var patron = /[\.\-]/ig; 
ID = ID.replace(patron, ""); 
var Coefs = [2,9,8,7,6,3,4,1]; 
var arrayID = ID.split( "" ); 
var Sum = 0;
var length = ID.length;
	for (i=0;i<length-1;i++){
	Sum = Sum + Coefs[i]*arrayID[i];
	}
	Sum = Sum + Coefs[7]*arrayID[length-1]; 	
		if ( (Sum % 10) != 0 ){
		swal({type : 'error' , title : 'Error!' , text: 'Alert: Incorrect Id'});
	}
}
Flokzu.onChange( [[Id Number]], validateId);


Validate identity card's numbers for table fields

function VerifyID(msg, data){
	var Array_CI = $(Flokzu.getAllColumnValues( [[Employee::Employee Id]] ));
	var Entries = ( Array_CI ).length;
	for(i=0; i<Entries; i++){
    	ID = Array_CI[i].innerText;
    	ID_Result = validateId(ID);
    	if(ID_Result == false){
        	Flokzu.error( [[Employee]] , "The number "+ID+" isn't valid." );
   		 swal({type : 'error' , title : 'Error!' , text: "The number "+ID+" isn't valid."});
   	 }
    }
}
Flokzu.onTableChange([[Employee::Employee Id]], VerifyID);


Dates
Calculate the Difference between two dates and show the result in days, months or years

function ChangeDate(msg, data){

var Date1 = moment(Flokzu.getFieldValue([[Date 1]]), "DD/MM/YYYY");
var Date2 = moment(Flokzu.getFieldValue([[Date 2]]), "DD/MM/YYYY");

var years = Date2.diff(Date1, 'years');
Date1.add(years, 'year');

var months = Date2.diff(Date1, 'months');
Date1.add(months, 'months')

var Days = Date2.diff(Date1, 'days');

Flokzu.setFieldValue([[Days]], Days);
Flokzu.setFieldValue([[months]], months);
Flokzu.setFieldValue([[Years]], years);
}

Flokzu.onChange([[Date 2]], ChangeDate);
Flokzu.onChange([[Date 1]], ChangeDate);


IMPORTANT: The Date 1 field should be prior to the Date 2 field

Identifier

Obtain the process instance identifier's number and insert it into a field

function copyReference(){
   var x = $('#fkz_ref').text();
   x = x.substring(x.lastIndexOf('-') + 1)
   Flokzu.setFieldValue([[FIELD]] , x);
}

Flokzu.onInit(copyReference);


Valid for tasks different than the initial one (Launch Process) since the instance's Id isn't created at that point yet.

Customize the identifier
For example, add the current year to the identifier "ABC-123" (2022-ABC-123):

function identifier(){
        var id=Flokzu.getFieldValue( [[Default Id]])
        var num=id.substring(id.indexOf("-")+1) + "-" + moment().format('YYYY')
        Flokzu.setFieldValue([[new Id]],num)
        }
Flokzu.onInit(identifier);


TABLES

Iterate and copy cells's values from a table field into text a field

function iteratecolumn(msg, data){   
  var rowCounter = 1;
    $( Flokzu.getAllColumnValues( [[Table::Column]] ) ).each(  
        function(){  
            var colValue = $(this).attr('value');
            if(rowCounter == 1){
                Flokzu.setFieldValue([[Field 1]],colValue);
            }else if (rowCounter == 2){
                Flokzu.setFieldValue([[Field 2]],colValue);
            }else if (rowCounter == 3){
                Flokzu.setFieldValue([[Field 3]],colValue);
            }
            rowCounter ++;
		}
	)
}
Flokzu.onAction(iteratecolumn);


Example:

function iterateTable(msg, data){   
    $( Flokzu.getAllColumnValues( [[table::column]] ) ).each( 
        function(){  
            //Throw an alert with the value
            alert( $(this).attr('value') ); 
        }
    );   
}
Flokzu.onTableChange( [[table::column]] , iterateTable );


Iterate a date-type column in a table and set a field with the minimum date from that column.

function dueDateTD1(msg, data){ 
    Flokzu.setFieldValue([[Minimum Date]],''); 
    $( Flokzu.getAllColumnValues([[Table::Column]])).each( 
        function(){  
            var Date = moment($(this).attr('value'), "DD/MM/YYYY");
            var dueDate = moment(Flokzu.getFieldValue([[Minimum Date]]), "DD/MM/YYYY");
            if(Flokzu.getFieldValue([[Minimum Date]])=='' || dueDate.isBefore(Date)){
                Flokzu.setFieldValue([[Minimum Date]],$(this).attr('value'));
 
            } else {
 
            }
        }
    );   
}
Flokzu.onTableChange([[Tabla::Column]], dueDateTD1);


Others

Buttons - Set a field as required according to a selected button

function functionName(msg, button) {
    hiddeReason(msg, button);
    if (button == 'Delete') {
       Flokzu.setRequired([[Field]]);
    }
}

Flokzu.onAction(functionName);


Sweet Alert with buttons and alert messages

function sweetAlert() {
       var Field1= Flokzu.getFieldValue([[Field Name 1]]);
       var Field2= Flokzu.getFieldValue([[Field Name 2]]);
       if (Field1=="Yes" && Field2=="Yes"){
			
		    swal({
			  title: "Insert title here",
			  text: "insert text message here",
			  type: "warning",
			  showCancelButton: true,
			  confirmButtonColor: "#DD6B55", //Red confirm button
			  confirmButtonText: "Yes",
			  cancelButtonText: "No",
			  closeOnConfirm: false,
			  closeOnCancel: false
			},
			function(isConfirm){
			  if (isConfirm) {
				swal("Ok!", "insert message here", "success");
				} else {
				swal("Insert Title Here", "Insert message here" , "error");
			  }
			});

        }
}
Flokzu.onChange([[Field1]], sweetAlert);
Flokzu.onChange([[Field2]], sweetAlert);


Modify a number format, insert currency symbol or decimals

const number = 123456.789;

console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number));
// expected output: "123.456,79 €"

// the Japanese yen doesn't use a minor unit
console.log(new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(number));
// expected output: "¥123,457"

// limit to three Yesgnificant digits
console.log(new Intl.NumberFormat('en-IN', { maximumYesgnificantDigits: 3 }).format(number));
// expected output: "1,23,000"
Was this article helpful?
Cancel
Thank you!