- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2024 02:05 PM
Hi - I customized a widget that we have internally that when clicked, it will popup another widget that shows a agreement that the customer must agree to. Once the checkbox is clicked and the user clicks "okay" - I would like for a file to be automatically downloaded to their machine.
I am having a hard time getting this to work. Can you all tell me how I can make this happen?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2024 01:47 AM
Sure, you can achieve this by using the $window service in AngularJS which is used in ServiceNow widgets. Here are the steps:
1. First, you need to inject the $window service in your client controller like this:
javascript
function($scope, $window) {
/* widget controller */
var c = this;
}
2. Then, you can use the $window service to download the file when the user clicks "okay". Here is a sample code:
javascript
c.downloadFile = function() {
if(c.data.agreementAccepted) {
var fileUrl = '/path/to/your/file';
$window.open(fileUrl, '_blank', '');
}
}
3. In the above code, replace '/path/to/your/file' with the actual URL of the file you want to download. The '_blank' parameter will open the file in a new window or tab, and the '' parameter is for specifying window features. In this case, no features are specified.
4. Finally, you need to call the c.downloadFile function when the user clicks "okay". You can do this by adding ng-click="c.downloadFile()" to your "okay" button in the HTML template of your widget.
Here is how the final code might look like:
Client Controller:
javascript
function($scope, $window) {
/* widget controller */
var c = this;
c.downloadFile = function() {
if(c.data.agreementAccepted) {
var fileUrl = '/path/to/your/file';
$window.open(fileUrl, '_blank', '');
}
}
}
HTML Template:
html
Okay
Remember to test your widget thoroughly to ensure it works as expected.
For ServiceNow Live Classes, Books, Sample Resumes, Interview Questions, CSA Quizzes.
And getting better services's on ServiceNow you can visits our website.
Please visit : https://nowkb.com/home
Our Website :https://nowkb.com/home
nowKB.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2024 01:47 AM
Sure, you can achieve this by using the $window service in AngularJS which is used in ServiceNow widgets. Here are the steps:
1. First, you need to inject the $window service in your client controller like this:
javascript
function($scope, $window) {
/* widget controller */
var c = this;
}
2. Then, you can use the $window service to download the file when the user clicks "okay". Here is a sample code:
javascript
c.downloadFile = function() {
if(c.data.agreementAccepted) {
var fileUrl = '/path/to/your/file';
$window.open(fileUrl, '_blank', '');
}
}
3. In the above code, replace '/path/to/your/file' with the actual URL of the file you want to download. The '_blank' parameter will open the file in a new window or tab, and the '' parameter is for specifying window features. In this case, no features are specified.
4. Finally, you need to call the c.downloadFile function when the user clicks "okay". You can do this by adding ng-click="c.downloadFile()" to your "okay" button in the HTML template of your widget.
Here is how the final code might look like:
Client Controller:
javascript
function($scope, $window) {
/* widget controller */
var c = this;
c.downloadFile = function() {
if(c.data.agreementAccepted) {
var fileUrl = '/path/to/your/file';
$window.open(fileUrl, '_blank', '');
}
}
}
HTML Template:
html
Okay
Remember to test your widget thoroughly to ensure it works as expected.
For ServiceNow Live Classes, Books, Sample Resumes, Interview Questions, CSA Quizzes.
And getting better services's on ServiceNow you can visits our website.
Please visit : https://nowkb.com/home
Our Website :https://nowkb.com/home
nowKB.com