Unable to Validate Variables in Multi Row Variable Set

LokeshwarRV
Tera Contributor

I have created one MRVS and inside i have created variable application name. But I am unable to validate if add the same application name in diff rows it should display errormsg for on Change. 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || !newValue) return;
 
    var eneteredValues = [];
    if(eneteredValues.includes(newValue)){
        g_form.clearValue('application_name');
        g_form.showFieldMsg('application_name', 'Application name already exists in another row.', 'error');
    }
eneteredValues.push(newValue);  
 
 
1 ACCEPTED SOLUTION

J Siva
Tera Sage

Hi @LokeshwarRV 
Create On Submit client script on the variable set as below.

function onSubmit() {

    var mrvs = g_service_catalog.parent.getValue("<YOUR VARIABLE SET NAME>");
    if (!mrvs) {
        return true;
    }
    var arr = JSON.parse(mrvs);

    var app_name = g_form.getValue("application_name");
    var duplicate = arr.some(row => row.application_name === app_name);

    if (duplicate) {
        g_form.addErrorMessage('Application name already exists in another row. Invalid insert');
        return false;
    }

}

Regards,
Siva

View solution in original post

1 REPLY 1

J Siva
Tera Sage

Hi @LokeshwarRV 
Create On Submit client script on the variable set as below.

function onSubmit() {

    var mrvs = g_service_catalog.parent.getValue("<YOUR VARIABLE SET NAME>");
    if (!mrvs) {
        return true;
    }
    var arr = JSON.parse(mrvs);

    var app_name = g_form.getValue("application_name");
    var duplicate = arr.some(row => row.application_name === app_name);

    if (duplicate) {
        g_form.addErrorMessage('Application name already exists in another row. Invalid insert');
        return false;
    }

}

Regards,
Siva