Skip to main content
Technical Documentation

Technical documentation to help users set up new or existing validation rules in ForceManager.

Training avatar
Written by Training
Updated over 5 months ago

INTRODUCTION

Custom validations are a type of customization that lets you validate data before sending the information through the website. The records are not updated/created if a custom validation returns an error.

1. ACTIVATE CUSTOM VALIDATIONS

Activate CV using the following query.

update tblConfigItems set PorDef = 1, fModificado = getdate(), UserModificado = 51 where codigo = 'customValidations'

2.TABLE STRUCTURE

There is just one table involved in the configuration of custom validations.

  • tblCustomValidations: for each different field to validate a row is needed.

Field

Description

entity

empresas, oportunidades

field

email, tel, Z_nif (exact name that appears in tblCamposStandard, tblCamposExtra)

name

exact name of the function (validateNif, validateTel)

description

description of the validation

type

string “validation“

scope

string “field“

action

string “onSave”

bucket

url of the function (https://fmcustomactions.s3-eu-w…….)

We have to provide to Support department the name and the JS function, they will give us the url to set into the bucket field of tblCustomValidations

3.- FUNCTION STRUCTURE AND EXAMPLES

STRUCTURE

The custom validation function must always return a message. If the message contains a string different from '' or with length > 0 the app will detect it as an error and it will show the string on the different applications.

var handler = function (value) { if (value) { let error = ''; const fieldRexp = / --REGEX EXPRESION-- /i; const string = ((value == null) ? "" : value).toString().toLowerCase(); if (!fieldRexp.test(string)) { return error = 'error text'; } else { return error; }} }

The validation can use a Regex expression. You can evaluate the expression before submitting it on this website -> https://regex101.com/

VALIDATE CP ES (validateCpEs)

var handler = function (value) { if (value) { let error = ''; const cpRexp = /^(?:0[1-9]\d{3}|[1-4]\d{4}|5[0-2]\d{3})$/i; const string = ((value == null) ? "" : value).toString().toLowerCase(); if (!cpRexp.test(string)) { return error = 'CP no válido'; } else { return error; }} }

VALIDATE EMAIL (validateEmail)

var handler = function (value) { if (value) { let error = ''; const emailRexp = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/; const string = ((value == null) ? "" : value).toString().toLowerCase(); if (!emailRexp.test(string)) { return error = 'La dirección de email no es válida'; } else { return error; }} }

VALIDATE TEL ES (validateTelEs)

var handler = function (value) { if (value) { let error = ''; const telRexp = /^(\+34|0034|34)?[6789]\d{8}$/; const string = ((value == null) ? "" : value).toString().toLowerCase(); if (!telRexp.test(string)) { return error = 'Teléfono no válido'; } else { return error; }} }

VALIDATE NIF ES (validateNif)

var handler = function (value) { if (value) { let error = ''; const dniRexp = /^(\d{8})([A-Z])$/i; const cifRexp = /^([ABCDEFGHJKLMNPQRSUVW])(\d{7})([0-9A-J])$/i; const nieRexp = /^[KLMXYZ]\d{7,8}[A-Z]$/i; const string = ((value == null) ? "" : value).toString().toLowerCase(); if (!dniRexp.test(string) && !nieRexp.test(string) && !cifRexp.test(string) ) { return error = 'NIF no válido'; } else { return error; }} }

Did this answer your question?