How do you get a list collectors value with onChange client script?

ericgilmore
Tera Guru

ver. London

I have a List Collector on a catalog item.

With settings:

  • | Type specifications tab |
    • List table [ A Table with a few items ]
  • | Default Value tab |
    • Variable attributes [ no_filter,glide_list ]

I'm trying to do 2 things.

  1. Using an onChange client script, just push the result out to a g_form.addInfoMessage() so I know it's there.
  2. Using an IF workflow activity, get the value so I can use it in the conditional

The list collector when activated in Platform or Portal works as expected, but I can't seem to get to the actually values represented therein.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
	var theValue = g_form.getValue(newValue);

	// I get nothing here...
	g_form.addInfoMessage("This should be the list collector value " + theValue);
	
// 	var lstr = g_form.getValue(newValue).toString();
// 	var thingsChosen = lstr.split(",");

// 	for(i=0; i<thingsChosen.length; i++){
// 		var temp = '';
// 		var thing = new GlideRecord('u_roll_on_equipment');
		
// 		thing.addQuery('sys_id',thingsChosen[i]);
// 		thing.query();
		
// 		if(thing.next()){
// 			temp = thing.u_equipment;
// 		}

		// I get nothing here when section un-commented		
// 		g_form.addInfoMessage('this is temp ' + temp);
		
// 	}
   
}

 In the workflow using the IF activity, where I also get no love...

IF workflow activity

Conditions
 condition [Variables][My Catalog Item][List Collector Variable][contains][ Smoothie ]

What's the trick to accessing these values?

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

This is for using it in server script, but the same premise should work for client, you'd just need to use g_form instead:

https://community.servicenow.com/community?id=community_question&sys_id=bc4a47a9db5cdbc01dcaf3231f96...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

4 REPLIES 4

Allen Andreas
Administrator
Administrator

Hi,

This is for using it in server script, but the same premise should work for client, you'd just need to use g_form instead:

https://community.servicenow.com/community?id=community_question&sys_id=bc4a47a9db5cdbc01dcaf3231f96...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

So I guess my logic/code was just wrong with the onChange, because this works. Thank you Allen A.

var theValue = g_form.getDisplayValue('The Field').toString(); //newValue.toString();
	var list = theValue.split(",");
	
	for (i=0; i<list.length; i++) {
		g_form.addInfoMessage("This should be the list collector value " + list[i]);
	}

 

So now, the workflow value? Also, I thought g_form.getDisplayValue was going away?

IF statement in workflow....you'd have to use current.variables.name_of_list, etc. in same context as g_form. So you can set a variable to the current.variables.name_of_list, if you want.

var listValue = current.variables.name_of_list.toString()...then split it etc. as referenced above.

And I haven't heard of displayvalue going away...works through Madrid and all that now anyway.

Please mark answer as Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Allen,

What I did was to find the sys_id and stick it in there. It works now. But I'll try the current.variables.VARNAME too.

Thanks for all your help.