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

prashanth2
Kilo Guru

Hi,

you can try this out,

Add sn-on-change="c.valueSelected(selectedValue)" in HTML as below:

<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" sn-on-change="c.valueSelected(selectedValue)" required></sn-choice-list>

 

Client Script: 

//add this in your client script

c.valueSelected = function(selectedValue)
{
c.data.selectedCountry = selectedValue;
c.server.update();
}

 

Server script:

// finally you can check if input is provided or not and access it as below in server script

if(input)                           
gs.addInfoMessage(input.selectedCountry);

 

Hope this solves the issue.

 

No this does not work. The client script is throwing error.

Could you add a screenshot showing the script and also a screenshot of the error

gs.addInfoMessage(input.selectedCountry);

 

gives me output: [object object]

 

when i print the value in client side there also getting the same output:

c.valueSelected = function(selectedValue) {
c.data.selectedCountry = selectedValue;
alert(c.data.selectedCountry);

};

 

i am getting the object instead of the exact selected value