Catalog Client Script| List Collector

ankitaankit
Tera Contributor

Hi team,

Please help me with below requirement.

I have a field named "Catalog Items" which is a list collector kind of field in which we get catalog items names as per filter. My requirement is whenever user selects the Catalog Items as " Created new user", then no other selection with this be allowed and user should get an alert saying, " With catalog Item Created new user no other selection can be done"

And the Catalog Item slush bucket should either get cleared or get set with value " Created new user".

How can we achieve it using Catalog Client Script.

Please help me with this.

 

Regards,

Ankit

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

This Catalog Client Script onChange of the List Collector variable will do that:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

	var varName = 'v_catalog_items'; //List collector variable name
    var catItem = '2c0f0d6c53411250324c17c0a0490ee0'; //Catalog Item to only allow single selection.
    var catArr = newValue.split(',');
	if (catArr.length > 1) { //don't need to check if there's only one selection
	    for (var i = 0; i < catArr.length; i++) {
			if (catArr[i] == catItem) { //a Catalog Item selected is the single selection one 
				alert('With catalog item "Created new user" no other selection can be done.');
        	    var leftBucket = gel(varName + '_select_0'); 
            	var rightBucket = gel(varName + '_select_1');
            	var selectedOptions = rightBucket.options;
            	var selectedIDs = new Array();
            	var index = 0;
            	for (var j = 0; j < selectedOptions.length; j++) {
                	if (selectedOptions[j].value != catArr[i]) {
                    	selectedIDs[index] = j;
                    	index++;
                	}
				}
            	moveSelectedOptions(selectedIDs, rightBucket, leftBucket); //clear Selected slushbucket
				break;
			}
        }
    }
}

After saving the script, ensure the Isolate script box is unchecked as this solution uses DOM manipulation

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

This Catalog Client Script onChange of the List Collector variable will do that:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

	var varName = 'v_catalog_items'; //List collector variable name
    var catItem = '2c0f0d6c53411250324c17c0a0490ee0'; //Catalog Item to only allow single selection.
    var catArr = newValue.split(',');
	if (catArr.length > 1) { //don't need to check if there's only one selection
	    for (var i = 0; i < catArr.length; i++) {
			if (catArr[i] == catItem) { //a Catalog Item selected is the single selection one 
				alert('With catalog item "Created new user" no other selection can be done.');
        	    var leftBucket = gel(varName + '_select_0'); 
            	var rightBucket = gel(varName + '_select_1');
            	var selectedOptions = rightBucket.options;
            	var selectedIDs = new Array();
            	var index = 0;
            	for (var j = 0; j < selectedOptions.length; j++) {
                	if (selectedOptions[j].value != catArr[i]) {
                    	selectedIDs[index] = j;
                    	index++;
                	}
				}
            	moveSelectedOptions(selectedIDs, rightBucket, leftBucket); //clear Selected slushbucket
				break;
			}
        }
    }
}

After saving the script, ensure the Isolate script box is unchecked as this solution uses DOM manipulation