The CreatorCon Call for Content is officially open! Get started here.

Catalog Client Script - OnChange or OnSubmit

Donna Kunkle
Tera Contributor

Is it possible to use a Catalog Client Script to verify that an entry is unique?
i.e. I have a select box (Yes/No) where there can only be one record with a "Yes" value.  (There can be multiple records with a "No" value.)

Is it possible to check for this when they add the record but before they submit the form.
The select box is on a Variable Set, where multiple entries can be added.


1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Donna,

For the best user experience, I would recommend doing this with an onChange Catalog Client Script that Applies to 'A Variable Set' (your MRVS) not 'A Catalog Item' when the select box variable changes.  Your script will look something like this:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
	
    if (newValue == 'Yes') {
        var mrvs = g_service_catalog.parent.getValue('mrvs1'); //MRVS internal name
        if (mrvs.length>2) { //native UI empty MRVS = '[]' which causes a JSON error
            var obj = JSON.parse(mrvs);
            for (var i = 0; i < obj.length; i++) {
                if(obj[i].variable_name == newValue) { //replace with your variable name
                    g_form.clearValue('variable_name');
                    alert('Yes has already been selected in another row.');
                }
            }
        }
    }
}

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

Hi Donna,

For the best user experience, I would recommend doing this with an onChange Catalog Client Script that Applies to 'A Variable Set' (your MRVS) not 'A Catalog Item' when the select box variable changes.  Your script will look something like this:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
	
    if (newValue == 'Yes') {
        var mrvs = g_service_catalog.parent.getValue('mrvs1'); //MRVS internal name
        if (mrvs.length>2) { //native UI empty MRVS = '[]' which causes a JSON error
            var obj = JSON.parse(mrvs);
            for (var i = 0; i < obj.length; i++) {
                if(obj[i].variable_name == newValue) { //replace with your variable name
                    g_form.clearValue('variable_name');
                    alert('Yes has already been selected in another row.');
                }
            }
        }
    }
}

Brad,
Thank You!  I will give this a try and let you know how it works out.

Brad, 
That worked perfectly!  Thank You!

You are welcome!