I wanted to create a multiselect type field on widget can anyone help on this question

RahamatMd
Tera Contributor

Hi All,

I wanted to create a multi select/list collector type field(not checkbox) values to be reference to choices table, could any one help on this

Thanks,
MD

2 REPLIES 2

Akash4
Kilo Sage
Kilo Sage

Hello,

Here are some steps that might help you. If the Multi-select/List field is not created on target required table, please do so as first step (provide the reference as sys_choice table as required)

HTML of the Widget looks something like this:

<div>
    <label for="multiSelect">Select Choices</label>
    <select id="multiSelect" class="form-control" multiple>
        <option ng-repeat="choice in c.data.choices" value="{{choice.value}}">
            {{choice.label}}
        </option>
    </select>
</div>

Define a Client side as follows:

(function() {
var choices = [];
var grChioce = new GlideRecord('sys_choice');
    grChioce.addQuery('name', <yourTable>);
    grChioce.addQuery('element', <yourField>);
    grChioce.query();
    while (grChioce.next()) {
        choices.push({
            value: grChioce.value.toString(),
            label: grChioce.label.toString() //adding Label is required for display purpose
        });
    }
data.choices = choices;
})(); //self calling function, no need to call again

 Hope this helps!

Regards, Akash

_____________________________________________________________________________

Please mark it as helpful👍 or Accept Solution✔️ based on the response to your query.

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

RahamatMd
Tera Contributor

Thanks for the reply @Akash4 .

 

i have used sn-record-picker for my above ask.