Autopopopulate value on right slush bucket on the basis of result from Script include

Vividha Garg
Tera Expert

I am trying to populate value in right slush bucket on the basis of results from Script include. 

It populates the right slush bucket as expected. But when I submit the form, it shows mandatory field error for this List collector variable. However, it already has values populated from script include results. After just clicking any value on right slush bucket , it allows to submit. Not able to understand the reason.

Below are the codes :

 

SCRIPT INCLUDE

getParticipants: function() {

var part = '';
var participants = this.getParameter('sysparm_participants');
var loc1 = new GlideRecord('sys_user');
loc1.addQuery('sys_id', 'IN', participants);
loc1.query();
while (loc1.next()) {
if (part == '')
part = loc1.sys_id + '**' + loc1.name;
else {
part = part + ',' + loc1.sys_id + '**' + loc1.name;
}
}
gs.log("Part--"+part,'GlideRidac');
return part;

},

 

CLIENT SCRIPT (onChange of a variable)

addClassroomParticipants('u_classroom_participants', values[23]);  //values[23] has sys_ids of user (comma separated)

function addClassroomParticipants(varname, participants) {
var varName = varname;
var participnts = participants;
var leftBucket = gel(varName + '_select_0');
var rightBucket = gel(varName + '_select_1');

var ga = new GlideAjax('GlideRecordRidac');
ga.addParam('sysparm_name', 'getParticipants');
ga.addParam('sysparm_participants', participants);
ga.getXML(setUserData);

function setUserData(response) {
var answer = response.responseXML.documentElement.getAttribute("answer").split(",");
for (var i = 0; i < answer.length; i++) {
var loc1 = answer[i].split('**');

var option = document.createElement("option");
option.value = loc1[0].toString(); //loc1.sys_id;
option.text = loc1[1]; //loc1.name;
rightBucket.add(option);
}
}
moveSelectedOptions('', leftBucket, rightBucket, '--None--');
sortSelect(leftBucket);
//sortSelect(rightBucket);
}

Please let me know if anyone has solution for it.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Vividha Garg 

check my blog on how to set list collector based on other variable

try to use that script

If my blog helps please mark it helpful and also bookmark it

Dynamically set list collector on change of variable

Regards
Ankur

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

View solution in original post

7 REPLIES 7

Saurav11
Kilo Patron
Kilo Patron

Hello

At the end why is it showing sortSelect(rightBucket) commented out.

It sould be tge one in the code and comment out sortSelect(leftBucket)

Please mark answer correct/helpful based on impact Thanks.

Hi Saurav,

Tried after doing this change, values are autopopulated as earlier but still it is not allowing to submit and shows List collector field mandatory error. 

Hello

You can check the below thread you may find your answer

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

Please mark answer correct/helpful based on impact

Hi Saurav,

I tried after doing changes, still the same issue is coming.