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

Create a multiselect/list collector field in a custom Widget and map to a table in service now

Jojolo
Kilo Contributor

I am trying to create a list collector field in a custom form widget.

I have populated the list using an array in the server script.

However when I try to map this form widget to the table field in backend of servicenow the value is blank.  If I remove the *multiple="multiple" in line 3 below,  I am able to select one item from the dropdown and this value gets mapped to the table field correctly.  Does anyone know a good way to map a multiselect field on the portal to a list collector in the system?

HTML

<div class="form-group col-lg-4">
<label class="col-lg-4 control-label" for="specialty">Specialties:</label>
<select id="specialty" name="specialty" class="form-control" multiple="multiple"
ng-model="c.specialty"
ng-options="specialty.name for specialty in c.data.specialties">
</select>
</div>

Client script

c.data.specialty = c.specialty;
c.data.specialtySysId = c.data.specialty.sys_id;

Server script

data.specialties = [];
var grSpecialty = new GlideRecord('u_contract_specialties');
grSpecialty.orderBy('u_specialty');
grSpecialty.addEncodedQuery('u_type=specialty');
grSpecialty.query();

while(grSpecialty.next()){
data.specialties.push({
'name': grSpecialty.getValue('u_specialty'),
'sys_id': grSpecialty.getUniqueValue()
});

if(input) {

var grNewReq = new GlideRecord('u_joinder');
grNewReq.initialize();

grNewReq.setValue('u_specialties', input.specialtySysId);

}

 

 

1 REPLY 1

Jace Benson
Mega Sage

Is this on a catalog item?  Can you provide how to set this up so others can try it to help you?

 

When asking a question about a problem caused by your code, you will get much better answers if you provide code (which you did) people can use to reproduce the problem. That code should be…

  • Minimal – Use as little code as possible that still produces the same problem
  • Complete – Provide all parts needed to reproduce the problem
  • Verifiable – Test the code you're about to provide to make sure it reproduces the problem


https://stackoverflow.com/help/mcve