Client Catalog script to move list collector options to selected in slushbucket onLoad

Nigel10
Tera Contributor

Hi There,

 

I have a List Collector variable on a catalog item called "Role" which references the "question_choice" table. After filtering it has four available options. Role 1, Role 2, Role 3, and Role 4. I need a client catalog script that when the form loads, if the value of a "Role_preset" variable is set to "Software Developer, i want the script to add Role 1 and Role 2 to the right side of the slushbucket.

 

I have tried a whole bunch of things but cant for the life of me get a script to move items from the left to the right. Any help would be much appreciated. I have something similar working for multiple choice variables but not list collectors. Below is currently what im trying. 

function onLoad() {
// Get the value of the "role_preset" variable
var rolePresetValue = g_form.getValue('variables.role_preset');

// Preselect options in the "Role" list collector variable based on the "role_preset" value
if (rolePresetValue === 'Software Developer') {
// Use pipe-separated values for the options to preselect
g_form.setValue('Role', '86f1c2aa1ba729100ee7eac2604bcb94|4542ce6a1ba729100ee7eac2604bcba0');
}
}

7 REPLIES 7

@Nigel10 

then write onChange catalog client script on that role_preset variable and populate the list collector.

refer my blog which does something similar and enhance it

Dynamically set list collector on change of variable 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I have tried switching to the SN guru slushbucket move method but still no luck. This is what im running now but i never get passed alert 5 

function onLoad() {
  // Get the value of the "role_preset" field
  var rolePresetValue = g_form.getValue('role_preset');
	alert("got role preset"+ rolePresetValue)

  // If "role_preset" is "Software Developer", preselect options in the "Role" list collector variable
  if (rolePresetValue === 'Software Developer') {
	  alert("1")
    var varName = 'Role';
	alert("2")

    var leftBucket = gel(varName + '_select_0');

		  alert("3")

    var rightBucket = gel(varName + '_select_1');

		  alert("4")

    var selectedIDs = ['86f1c2aa1ba729100ee7eac2604bcb94','4542ce6a1ba729100ee7eac2604bcba0'];

	  alert("5")

    // Move the selected options from left to right
    moveSelectedOptions(selectedIDs, leftBucket, rightBucket, '--None--');

		  alert("6")


    // Sort the options in the right bucket
    sortSelect(rightBucket);
		  alert("7")

  }
}

Hi @Nigel10. Did you ever figure this out? Running into the same issue. Thanks.