Get value of sn-choice-list in server script in widget

SD35
Tera Expert

I have a sn-choice-list as such:

Which shows me list of countries.

<sn-choice-list sn-model="c.cmp_country" id="cmp_country" name="cmp_country" placeholder="${Company Country}" field="country" sn-options="data.cnt" sn-value-field="value" sn-text-field="label" sn-items="data.cnt" page-size="10" required></sn-choice-list>

How to i fetch the value selected in server script ?

1 ACCEPTED SOLUTION

Change it as below, and add ".toString()" while getting the value from a GlideRecord [cnt.sys_id.toString()].

 

find_real_file.png

View solution in original post

12 REPLIES 12

Have you tried seeing the value of the object using JSON.stringify(c.data.selectedCountry) or JSON.stringify(input.selectedCountry)

if i use this it gives me output: {"$$hashKey":"object:77"}

no country name, instead getting object:77

It seems to be working for me.find_real_file.png

I am actually fetching the country values from server side like this:

(using custom table as per client requirement)

data.cnt = [];

var cnt = new GlideRecord('x_vrm_lite_vrm_core_country');
cnt.addEncodedQuery('active=true');
cnt.orderBy('name');
cnt.query();
while (cnt.next()) {
var cntObj = {};
cntObj.label = cnt.name.toString();
cntObj.value = cnt.sys_id;
data.cnt.push(cntObj);

}

 

now how to I use this data.cnt in client script to populate the values.

Setting static values in client script are working fine for me as well.

If I am able pass data.cnt in client script then I thing it will work for me.

Change it as below, and add ".toString()" while getting the value from a GlideRecord [cnt.sys_id.toString()].

 

find_real_file.png