Auto Populate Service Portal List Collector Variable based on Selected Value from Select Box

mikekirschen
Giga Contributor

Hello,

I have requirements to automatically populate Service Portal Catalog Item List Collector variable based on Select Box variable entry.

I created relationship table u_teammate_position_profiles between Teammate Position and Teammate Profile

find_real_file.png

Position = u_position                                        

Profile  = u_profile

I was able to dynamically short list Teammate Position Roles (referenced to Profile) based on the selected Teammate Position (reference Position)

find_real_file.png

Manually selecting the Profiles (Roles)

find_real_file.png

The requirement is to automatically populate the List Collector Teammate Position Roles (teammate_position_roles) based on the selected Position. I know client script and script include probably the best method to implement but it is not working for me so far.

Assistance is greatly appreciated

 

Regards,

Mike

1 ACCEPTED SOLUTION
3 REPLIES 3

dvp
Mega Sage
Mega Sage

Below blog explains how to auto populate list collector in Portal

https://community.servicenow.com/community?id=community_blog&sys_id=571da2e5dbd0dbc01dcaf3231f961913

absd
Mega Contributor

Hi Dvp,

 

I have a similar requirement and i followed the same step exactly but am not able to get the same results. So basically i have one refernce variable Of Group table and another List collector Variable of User type. so whenever i select a group which has a field as "Ownership" and wen the ownership value is Customer.. i want to show only those list of user records which contains a particular phrase in their email id.

 

Client Script

----------------------------------------- 

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

//Type appropriate comment here, and begin script below
//g_form.setReadOnly('name',true);
var ga = new GlideAjax("test");
ga.addParam("sysparm_name","getUserDetails");
ga.addParam("sysparm_id",newValue);
//alert(newValue)
ga.getXML(setManager);


function setManager(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//gs.log("inclient"+answer);
alert('hello')
alert(answer)----->getting all the required value upto here
//addition
var arr = answer.split('||');

 

//arr[1] has the sys_id of the users

//arr[0] has the display name of the users

 

if (window === null)

g_form.setValue('add_group_members', arr[1], arr[0]);

else

addItemstoList('add_group_members', arr[1], arr[0]);

 

}

function addItemstoList(listCollector, sysid, display_value) {

var varName = listCollector;

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

var rightBucket = gel(varName + '_select_1');
var selectedOptionsIDs = [];
rightBucket.options.length = 0;
if (sysid != '') {

var myCIArray = sysid.split(',');

var displayvalue = display_value.split(',');

for(i=0; i < myCIArray.length; i++) {

var option = document.createElement('option');

option.value = myCIArray[i];

option.text = displayvalue[i];

// add the option to the bucket

rightBucket.add(option);

}

}

// sort the buckets

sortSelect(rightBucket);

moveSelectedOptions(selectedOptionsIDs, leftBucket, rightBucket, '--None--');


}
}

 

 

 

Script Include

-------------------------------------------------

 

var test = Class.create();
test.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getUserDetails:function(name){
// var answer=[];
var name_arr = [];
var sys_id_arr = [];
var userSysId = this.getParameter('sysparm_id');
var ga;
var gr = new GlideRecord("sys_user_group");
if(gr.get(userSysId))
{
gs.log('test1' +gr.u_ownership);
if(gr.u_ownership=="Customer")
{
gs.log('test2');
ga= new GlideRecord('sys_user');
ga.addEncodedQuery('emailLIKEaxisys');
ga.query();
while(ga.next())
{
//gs.log('users are'+answ er.push(ga.sys_id)) ;
name_arr.push(ga.name.toString());
sys_id_arr.push(ga.sys_id.toString);

}
}

}
gs.log('users are'+name_arr.length) ;
gs.log('object of user'+name_arr) ;
gs.log('sysid of user'+sys_id_arr) ;

// return sys_id_arr;
return name_arr.toString() + '||' + sys_id_arr.toString(); ----------> checked and it returns the desired result

}



});

 

 

My only issue is the list value is not getting pushed to that list collector variable in Portal.


Can you please let me know what wrong am doing.

 

For your ref we are working in London version

 

Thanks,,,

mikekirschen
Giga Contributor

Many thanks for information based on that I was able to modify the script and it is all working as expected. Here is a copy of the modified scripts, might be helpful for others:

 Script Include:

find_real_file.png

Catalog Item Client Script

find_real_file.png

find_real_file.png

 

Best regards,mike