- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2019 07:53 PM
We want to edit the way the ootb <sp-attachment-button> looks, where is this code located? Is there a way to change some styling for that button?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2019 10:04 PM
The code of <sp-attachment-button> is included in https://<yourinstance>.service-now.com/scripts/js_includes_sp.jsx or https://<yourinstance>.service-now.com/scripts/app.$sp/directive.spAttachmentButton.js. It's below:
/*! RESOURCE: /scripts/app.$sp/directive.spAttachmentButton.js */
angular.module('sn.$sp').directive('spAttachmentButton', function(cabrillo, $rootScope, i18n) {
'use strict';
return {
restrict: 'E',
template: function() {
var inputTemplate;
if (cabrillo.isNative()) {
inputTemplate = '<button href="#" title="" ng-click="showAttachOptions()" class="panel-button sp-attachment-add btn btn-link" aria-label=""><span class="glyphicon glyphicon-camera"></span></button>';
} else {
inputTemplate = '<input type="file" style="display: none" multiple="true" ng-file-select="attachmentHandler.onFileSelect($files)" class="sp-attachments-input"/>';
inputTemplate += '<button title="" ng-click="attachmentHandler.openSelector($event)" class="panel-button sp-attachment-add btn btn-link" aria-label=""><span class="glyphicon glyphicon-paperclip"></span></button>';
}
return ['<span class="file-upload-input">', inputTemplate, '</span>'].join('');
},
controller: function($element, $scope) {
$scope.showAttachOptions = function() {
var handler = $scope.attachmentHandler;
cabrillo.attachments.addFile(handler.tableName, handler.tableId, null, {
maxWidth: 1000,
maxHeight: 1000
}).then(function(data) {
handler.getAttachmentList();
$rootScope.$broadcast("added_attachment");
}, function() {
console.log('Failed to attach new file');
});
}
;
$scope.$on('attachment_select_files', function(e) {
$scope.$evalAsync(function() {
$($element).find('.sp-attachments-input').click();
});
});
},
link: function(scope, el, attr) {
i18n.getMessage("Add attachment", function(msg) {
el.find("button").attr("title", msg);
el.find("button").attr("aria-label", msg);
});
}
}
});
If you need to change the code you can modify it and save it as new directive under another name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2023 01:30 PM
Hi Yun,
Do you solve that problem, I am appreciate it if you share your solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2019 06:49 AM
It's very easy. I suppose that you never created your directive before. You need just type "angular" in menu to see the module "Angular Providers". On click on it you will see many directives, services and factories. You need just click "New" button, choose "Directive" as type (because angular.module('sn.$sp').directive(...) was originally). You place spFileAttachmentButton as Name and finally copy only the code starting with function(cabrillo, $rootScope, i18n) { and till the corresponding }. You can add any name for the anonymous function to prevent warning of code editor:
after saving the code you need open the widget where you use it. You should click on "Edit" button of related list "Anguler Providers" of your widget and add new directive spFileAttachmentButton to the list. After that you can use <sp-file-attachment-button> instead of <sp-attachment-button>.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2019 06:54 AM
got it! I deleted angular.module('sn.$sp').directive(...) and now it works fine, thanks!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2020 08:50 AM
Thankyou for this oleg, this helped me alot!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2021 11:01 PM
Hello;
Can we change table in this provider, as i don't want attachment to be stored in sys_attachment table i want to store attachment to custom table.
Please help me on this
Thanks
Pramod Pandey