- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2025 10:47 PM
I am trying to develop a simple button widget, just for learning purposes. My idea was to take the default link-button and make a "function button" such that it executes a function when it is clicked. The code is as follows:
HTML:
<button class="btn btn-{{options.color}} m-b" ng-click="funcio()">{{data.buttonMsg}}</button>
Server Script:
data.buttonMsg = gs.getMessage(options.button_text || "Click Here");
gs.log('Holaaa', 'WIDGET');
Client Script:
api.controller=function() {
/* widget controller */
var c = this;
$scope.funcio = function() {
var url = 'https://en.wikipedia.org/wiki/Microsoft_Office_XML_formats#Excel_XML_Spreadsheet_example';
window.open(url, '_blank');
};
};
Option Schema:
[{"name":"href","section":"Presentation","label":"Link for button","type":"string"},{"name":"button_text","section":"Presentation","label":"Contents of button","type":"string"}]
I have noticed that when I comment the client script, the logs appear in the [syslog] table while if I do use this $scope.funcio definition, the server script is no longer running. However, I have found many articles where the use this structure to launch functions via ng-click.
My questions are: why this command is preventing my server script from running? Where can I find more technical information about the $scope object (because I found no reference of this object on servicenow documentation)? How could I solve my issue?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2025 10:55 PM
@jordimsant
Try injecting the $scope into the function definition and see if it works!
api.controller=function($scope) {
/* widget controller */
var c = this;
$scope.funcio = function() {
var url = 'https://en.wikipedia.org/wiki/Microsoft_Office_XML_formats#Excel_XML_Spreadsheet_example';
window.open(url, '_blank');
};
};
Please mark this as helpful / accepted solution if it resolves your query.
Thanks & Regards
Veer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2025 10:55 PM
@jordimsant
Try injecting the $scope into the function definition and see if it works!
api.controller=function($scope) {
/* widget controller */
var c = this;
$scope.funcio = function() {
var url = 'https://en.wikipedia.org/wiki/Microsoft_Office_XML_formats#Excel_XML_Spreadsheet_example';
window.open(url, '_blank');
};
};
Please mark this as helpful / accepted solution if it resolves your query.
Thanks & Regards
Veer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2025 11:00 PM
I am ashamed, it was so simple 😂! However, I cannot understand why this solves my problem, do you know why?