How to use a script include for ng-change
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 10:59 AM
Hello,
I have a select box in a service portal widget that needs to update the user record when the selection changes. I have a script include that has the function to do this, but how do i get that script include function to run when the user changes what is in the dropdown? I have a ng-change in my html, but i am unsure how to handle this.
In the html, i have:
ng-change="setNewValue()"
and in the client controller. i have:
$scope.setNewValue = function() {
}
Let me know if any more info is needed. thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 11:18 AM
I wouldn't use an ng-change, but rather do this:
function($scope, $rootScope) {
var c = this;
$rootScope.$on("field.change", function(evt, parms) {
if (parms.field.name == "name_of_my_select_box") {
c.server.get({action : 'trigger_script_include'}).then(function(response) {
console.warn('response: '+response.data.resp);
});
}
});
}
From there, just use the "Server" script area to do what your script include is doing. No need for the script include since you can just do everything within your widget.
However, if you want to call the script include, that's easy too... just make sure you've set it up correctly, then on your "Server" code in your widget, just call it. Example:
(function() {
if (input) {
if (input.action == 'trigger_script_include') {
var si = new name_of_my_script_include();
var resp = si.doThisFunction();
data.resp = resp;
}
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 12:23 PM
Thanks..if i did it this way, i am trying to figure out how this would work in my situation...
for "field.change", what field would i need to put here? and the function(evt, parms)..do i need to change those arguments?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 01:02 PM
If you want to use your ng-change, that's fine. Your ng-change function would look something like this:
$scope.setNewValue = function() {
c.server.get({action : 'trigger_script_include'}).then(function(response) {
console.warn('response: '+response.data.resp);
});
}
But what I'm wondering is are you passing that new value to your script include? Are you using "ng-model" on the element you're executing the ng-change on?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 01:43 PM
Yes i am using ng-model. And yes i am passing that new value to the script include. For the c.server.get action, where i am defining 'trigger_script_include'? what would that be?