Validate the lenght of a dield, based on another field in another table.

Facundo Prado
Tera Expert

Hello everyone!
I need to validate the lenght of this "IBAN code" field (Thisi is a Record Producer):

FacundoPrado_0-1696957765118.png


Based on this field in another table:

FacundoPrado_1-1696957855553.png


A little explanation: I need to validate IBAN codes, but the IBAN are different for each country. So I need the validation depends on the country I select.

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Facundo Prado In order to implement this functionality, you need to implement the following.

1. Create a Script Include: Create a client callable script include as follows.

Screenshot 2023-10-10 at 11.02.12 PM.png

Here is the script include code.

var MyUtilsV2 = Class.create();
MyUtilsV2.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    initialize: function() {},
	getIBANFormat:function(){
		var glideRecord = new GlideRecord('cmn_location');//Replace table with your table name
		glideRecord.addQuery('country',gs.getUser().country);
		glideRecord.query();
		var iBAN= '';
		if(glideRecord.next()){
			iBAN=glideRecord.getValue('ibancodes'); //replace name with your IBAN format column name
		}
		return iBAN;
	},
    
    type: 'MyUtilsV2'
});

2. Create an onChange Client script on iBAN filed on your record producer.

Screenshot 2023-10-10 at 11.09.17 PM.png

Here is the code.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ga = new GlideAjax('HelloWorld'); 
    ga.addParam('sysparm_name', 'getIBANFormat'); 
    
    ga.getXML(getIBANFormatResponse);
   
    function getIBANFormatResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var ibanFieldValue = g_form.getValue('iban_code');
		if(answer.test(ibanFieldValue)){
			alert('iban is correct');
		}
		else{
			alert('invalid data');
		}
    }
}

Please make the appropriate changes in the script to match with your existing implementation.

 

Hope this helps,

View solution in original post

3 REPLIES 3

SANDEEP28
Mega Sage

@Facundo Prado Only length of IBAN code should match or it should be exactly same as in the another table ?

It should be exactly the same "length" as in the table.

Sandeep Rajput
Tera Patron
Tera Patron

@Facundo Prado In order to implement this functionality, you need to implement the following.

1. Create a Script Include: Create a client callable script include as follows.

Screenshot 2023-10-10 at 11.02.12 PM.png

Here is the script include code.

var MyUtilsV2 = Class.create();
MyUtilsV2.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    initialize: function() {},
	getIBANFormat:function(){
		var glideRecord = new GlideRecord('cmn_location');//Replace table with your table name
		glideRecord.addQuery('country',gs.getUser().country);
		glideRecord.query();
		var iBAN= '';
		if(glideRecord.next()){
			iBAN=glideRecord.getValue('ibancodes'); //replace name with your IBAN format column name
		}
		return iBAN;
	},
    
    type: 'MyUtilsV2'
});

2. Create an onChange Client script on iBAN filed on your record producer.

Screenshot 2023-10-10 at 11.09.17 PM.png

Here is the code.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ga = new GlideAjax('HelloWorld'); 
    ga.addParam('sysparm_name', 'getIBANFormat'); 
    
    ga.getXML(getIBANFormatResponse);
   
    function getIBANFormatResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var ibanFieldValue = g_form.getValue('iban_code');
		if(answer.test(ibanFieldValue)){
			alert('iban is correct');
		}
		else{
			alert('invalid data');
		}
    }
}

Please make the appropriate changes in the script to match with your existing implementation.

 

Hope this helps,