Get selected value from html select in widget

Jonathan Monks
Tera Guru

Hoping you can help with this!

I am building a widget to escalate tasks and I have created a select box to drop down the assignment group for them to go to.

<select id="group_name" name="group_name" model="c.data.selectedgroup">
<option disabled hidden style='display: none' value=''></option>
<option value="{{group.value}}" ng-repeat="group in data.groups" ng-selected="{{group.value == "12acb2770ffe8a00fdbdb0c362050e27}}">{{group.name}}</option>
</select> 

The box creates correctly as per the below, but how do I get the value in the server script?

find_real_file.png

The code I have for the server script is:

if (input) {
if (input.action == "escalate") {
gs.log('ESCALATION WIDGET - SysID - ' + data.sys_id); // works
gs.log('ESCALATION WIDGET - UserID - ' + data.user); // works
gs.log('ESCALATION WIDGET - group_name - INPUT - ' + input.group_name); // doesn't work
gs.log('ESCALATION WIDGET - selectedgroup - INPUT - ' + input.selectedgroup); // doesn't work
gs.log('ESCALATION WIDGET - group_name - DATA - ' + data.group_name); // doesn't work
gs.log('ESCALATION WIDGET - selectedgroup - DATA - ' + data.selectedgroup); // doesn't work
gs.log('ESCALATION WIDGET - Notes - ' + input.notes); // works
}
}

What am I missing?

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

I generally don't do this using the input. I assume you have a c.server.update() somewhere in your client script? The server script only runs on load and on update (from the client script.)

First thing I noticed was that model='c.data.selectedgroup' should be ng-model. Using that you can access the information in your client script as c.data.selectedgroup. Please provide more information of what you are trying to do with this data in the server script. it might make more sense in the client script via scripted REST API.

View solution in original post

3 REPLIES 3

Chuck Tomasi
Tera Patron

I generally don't do this using the input. I assume you have a c.server.update() somewhere in your client script? The server script only runs on load and on update (from the client script.)

First thing I noticed was that model='c.data.selectedgroup' should be ng-model. Using that you can access the information in your client script as c.data.selectedgroup. Please provide more information of what you are trying to do with this data in the server script. it might make more sense in the client script via scripted REST API.

Hello Chuck,

Amazingly I just watched a video on the service portal with you in it, and you replied to the question! What a small world 🙂

I changed the model to ng-model and it now works with input.selectedgroup, so its escalating tickets as it should. Slightly frustrating that I missed that, but I'm still learning.

Thanks for the help, Chuck - I always see you on Google searches and your answers have helped me a lot in the past year.

Jon

 

Thanks for watching. Glad it turned out to be something simple. FWIW, you're not the only one who misses little things like that. 🙂