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

onchange client script for a list collector

RudhraKAM
Tera Guru

I have a requirement on catalog item , on the change of a variable, a list collector will show up and we need to filter the values in the list collector (active=true) , i know we can achieve this  by defining the ref qual condition in the list collector but we have another use case . so can some one please help me with the code ?

 

Thanks in advance 

16 REPLIES 16

Zach Biewend1
Giga Expert

There may be a way to dynamically modify and run the filter like you're asking, which would probably be preferred. But if you can't find that, here's some code I've used to populate the buckets on either side of the list collector. 

// instantiate left and right buckets of the list collector
	var lb = gel( 'users_to_remove_select_0' );
	var rb = gel( 'users_to_remove_select_1' );
	var option;
	
	// remove all options in left bucket
	lb.options.length = 0;
	
	// add options to left bucket from object
	for ( var i = 0; i < obj.length; ++i ) {
		option = document.createElement( 'option' );
		option.value = obj[ i ].sid;
		option.text = obj[ i ].name;
		lb.add( option );
	}

So the first few lines of this code get the HTML elements. The format should be <variable_name>_select_0 and select_1. So in my example the variable is named 'users_to_remove'.

The full script calls a GlideAjax script include. I pass some input (a group name in this case) and the GlideAjax runs on the server to find a list of users. Then it returns that as a JSON object (obj). But the content of the for loop is what's important. 

option.value should be the sys_id of the record, and option.text is what will display in the client to the user. 

RudhraKAM
Tera Guru

can we have client script 

Mike Patel
Tera Sage

try below, I used it on CMS stie not on portal

function onLoad() {
	//Apply a default filter to the list collector variable
	var collectorName = 'app';
	var filterString;
	if (g_form.getValue('your variable') == 'xyz') {
		filterString = 'active=true';
	}else{
		filterString = '';
	}
	//Hide the list collector until we've set the filter
	g_form.setDisplay(collectorName, false);
	setCollectorFilter();
	
	function setCollectorFilter(){
		//Test if the g_filter property is defined on our list collector.
		//If it hasn't rendered yet, wait 100ms and try again.
		if (eval('typeof(' + collectorName + 'g_filter)') == 'undefined' ) {
			setTimeout(setCollectorFilter, 100);
			return;
		}
		//Find the filter elements
		var fil = gel('ep');
		var message = gel('app_select_0_add_remove_message_table');
		
		//Reset the filter query
		eval(collectorName + 'g_filter.reset()');
		eval(collectorName + 'g_filter.setQuery("' + filterString + '")');
		eval(collectorName + 'acRequest(null)');
		//Redisplay the list collector variable
		g_form.setDisplay(collectorName, true);
	}
}

unfortunately its on portal