snChoiceList Directive snOnChange issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2018 05:32 AM
Hi All,
Need some Service Portal widget expertise please. I'm having trouble getting the value out of a sn-choice-list field with an onchange. Here's my HTML:
<sn-choice-list
sn-on-change="c.valueSelected(attribute)"
sn-model="attribute.value"
sn-items="attribute.choices"
sn-value-field="value"
sn-text-field="display">
</sn-choice-list>
And my client script:
c.valueSelected = function(attribute) {
alert(attribute.value);
};
alert(attribute.value) is giving me the oldValue rather than newValue - guessing it's some asynchronous thing. Anyone know how to get the newValue directly on a change?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2018 08:07 AM
Use this as a sample: https://community.servicenow.com/message/1108400?_ga=2.151907833.1928901838.1516217168-1877748840.14...
It explains how everything works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2018 08:12 AM
Thanks, but that link does not explain how to use sn-on-change with a choice list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2018 08:31 AM
<sn-record-picker field="c.manager" table="'sys_user'" display-field="'name'" display-fields="'email'" value-field="'sys_id'" search-fields="'name'" page-size="100" placeholder="Manager" default-query="'name=Stefan Lutz'"></sn-record-picker>
This populates from "sys_user" table the "sn-record-picker". When a record is selected the script populates:
// Manager
c.manager = {
displayValue: "",
value: "",
name: 'managerfield'
};
You just have to take the "c.manager" and do at the client a c.server.update() and push the value to the server. Use a server script to save it.
Not sure what else is there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2018 08:18 AM
I am using a workaround at the moment, using setTimeout to look up the value of my field after it has been updated works, not ideal if you need to do something synchronously.
c.valueSelected = function(sys_id) {
setTimeout(function(){
//Look up my attribute object by sys_id
var attribute = searchArr(sys_id, c.data.docObj.attributes, "sys_id");
//attribute now has correct answer
alert(attribute.value);
}, 10);
};