How to Set Integer Validation for multiple Variables at a time.

VikramM1
Tera Contributor

Hi All,

 

I have created record producer mapping custom table fields. I have some integer fields in custom table. But, in Record producer variable type there is no integer option. Since, i selected single line text. 

 

Can someone help me how to set integer validation for multiple variables at a time.

 

Thanks,

1 ACCEPTED SOLUTION

@VikramM1 

You can modify the code something like below:

 

function onSubmit() {
   var variableNames = ['variable_name1', 'variable_name2', 'variable_name3'];
    for (var i = 0; i < variableNames.length; i++) {
        var inputValue = g_form.getValue(variableNames[i]);
        var intValue = parseInt(inputValue);
        
        if (isNaN(intValue)) {
            alert('Please enter a valid integer value for ' + variableNames[i] + '.');
            return false; // Prevent submission
        }
    }
    
    // Proceed with submission
    return true;
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

View solution in original post

5 REPLIES 5

Maddysunil
Kilo Sage

@VikramM1 

I think there isn't a direct "integer" variable type in record producers, you can still achieve integer validation using scripting.

You can attach a client script to the record producer variables and use JavaScript functions like parseInt() or regular expressions to ensure that the input is a valid integer.

basic example of how you might validate an input field as an integer using client-side:

 

function onSubmit() {
    var inputValue = g_form.getValue('variable_name'); // Replace 'variable_name' with the actual variable name
    var intValue = parseInt(inputValue);
    
    if (isNaN(intValue)) {
        alert('Please enter a valid integer value.');
        return false; // Prevent submission
    }
    
    // Proceed with submission
    return true;
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Hi Maddy Sunil,

 

Thanks for your reply. This will apply for a single variable. I want this to apply for multiple variables. Can you please modify code according and share. It will be more helpful.

@VikramM1 

You can modify the code something like below:

 

function onSubmit() {
   var variableNames = ['variable_name1', 'variable_name2', 'variable_name3'];
    for (var i = 0; i < variableNames.length; i++) {
        var inputValue = g_form.getValue(variableNames[i]);
        var intValue = parseInt(inputValue);
        
        if (isNaN(intValue)) {
            alert('Please enter a valid integer value for ' + variableNames[i] + '.');
            return false; // Prevent submission
        }
    }
    
    // Proceed with submission
    return true;
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Hi Maddysunil,

 

Its worked after submitimg what ever entered other than integer it removed value form that fields. But, it should not allow to submit the form. Its allowed.