- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 01:24 PM
I have a <sn-choice-list> field on a service portal widget where the field is defined as follows:
html:
<sn-choice-list
field="c.mychoice"
sn-model="c.mychoice"
sn-options="c.mychoicelistoption"
sn-value-field="myChoiceValue"
sn-text-field="myChoiceDisplay"
sn-items="c.mychoiceoptions"
sn-on-change="c.valueSelected(selectedValue)">
</sn-choice-list>
client script:
c.mychoiceoptions = [{
myChoiceDisplay: "Personal",
myChoiceValue: 'personal'
},
{
myChoiceDisplay: "Work Related",
myChoiceValue: 'work-related'
}];
c.mychoicelistoption = {
hideSearch: false
};
c.mychoice = "personal";
if I call
c.valueSelected = function(selectedValue){ alert(selectedValue); }
in the client script, then "personal" or "work-related" are returned as I would expect, but I have another <sn-choice-list> field defined as follows so I can get the options from sys_choice table in the server script:
html:
<sn-choice-list
field="c.wbsDefault"
sn-model="c.wbsDefault"
sn-options="c.wbsListOption"
sn-value-field="value"
sn-text-field="label"
sn-items="c.wbs"
sn-on-change="c.wbsSelected(wbsValue)">
</sn-choice-list>
client script:
c.wbs = [];
for(i = 0; i < c.data.wbsLabels.length; ++i){
c.wbs.push({
label: c.data.wbsLabels[i].toString(),
value: c.data.assetsValues[i]
});
}
c.wbsListOption = {
hideSearch: false
};
c.wbsDefault = "00000";
server script:
data.wbsLabels = [];
data.wbsValues = [];
var wbsGR = new GlideRecord("sys_choice");
wbsGR.addQuery('element', 'u_wbs');
wbsGR.query();
while(wbsGR.next()){
data.wbsLabels.push(wbsGR.getDisplayValue());
data.wbsValues.push(wbsGR.getValue());
}
if I call
c.wbsSelected = function(wbsValue){alert(wbsValue);}
in the client script, then 'undefined' is returned when I select a value for that field. How can I get the value of this field?
Thank you
Solved! Go to Solution.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 02:21 PM
Based on the code you just posted that the sn-model='<WHATEVER>' will put the data into the <WHATEVER>.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 02:21 PM
Based on the code you just posted that the sn-model='<WHATEVER>' will put the data into the <WHATEVER>.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2020 08:09 AM
Hi,
How can we assign the value which we get from the below choice list field to any field on the incident form in server script?
c.valueSelected = function(selectedValue){ alert(selectedValue); }
For ex. : selectedValue output is XYZ. I want this output to be inserted in the incident Description field.
Can you please help me with this requirement.
Regards,
Priya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2020 08:39 AM
Then you need to do something like this
//Client code to add to function
c.data.action = "addToIncident";
c.data.selectedValue = selectedValue;
$scope.server.update();
//Server side
if(input){
if(input.action && input.action == "addToIncident"){
//Do when ever work needs done with the input.selectedValue
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2020 09:43 AM
Hey Drew,
Below script we are using to import value to incident table field as action. Can you please check and let me know what is the issue in below script.
Body HTML template:
<div class="panel-body">
<label class="col-sm-2 control-label">CoworkerConcern</label>
<div class="col-sm-10">
<sn-choice-list
field="c.myCoworkerConcern"
sn-model="c.myCoworkerConcern"
sn-options="c.myCoworkerConcernlistoption"
sn-value-field="myChoiceValue"
sn-text-field="myChoiceDisplay"
sn-items="c.myCoworkerConcernoptions"
sn-on-change="c.valueSelected(selectedValue)">
</sn-choice-list>
</div>
</div>
Client script:
c.myCoworkerConcern = "Bank Inquiry";
c.valueSelected = function(selectedValue){
//alert(selectedValue);
}
Server script:
rec.u_action = input.myCoworkerConcern;