AttachmentHandler on Custom SP Widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2020 12:50 PM
I am modifying a custom SP widget which creates a request (sc_request) record. The requirement is for users to enter five (5) mandatory attachments. I haven’t yet started on the server code…now just trying to get the client side working first.
The error I’m getting is an empty table name (see log errors below) & no attachments on the request record. I’d like to put the 5 mandatory attachments on the client side (vs. server) to make the user experience better. I’m new to SP development and would appreciate any assistance.
GlideRecord.setTableName - empty table name: org.mozilla.javascript.EvaluatorException: GlideRecord.setTableName - empty table name:
com.glide.script.GlideRecord.setTableName(GlideRecord.java:635)
com.glide.script.GlideRecord.initTableName(GlideRecord.java:347)
com.glide.script.GlideRecord.<init>(GlideRecord.java:329)
com.glide.ui.SysAttachment.writeParts(SysAttachment.java:419)
HTML
<div>
Select Attachments: <sp-attachment-button></sp-attachment-button>
</div>
Client
/* --------------------- */
* Attachments Functions [START] */
/* --------------------- */
$scope.stickyHeaderTop = '0px';
$scope.$on('dialog.upload_too_large.show', function(e){
$log.error($scope.m.largeAttachmentMsg);
spUtil.addErrorMessage($scope.m.largeAttachmentMsg);
});
$scope.m = $scope.data.msgs;
var ah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, appendError);
function appendError(error) {
spUtil.addErrorMessage(error.msg + error.fileName);
}
ah.setParams($scope.data._attachmentTable, $scope.data.recordID, 1024 * 1024 * $scope.data.maxAttachmentSize);
function setAttachments(attachments, action) {
$scope.attachments = attachments;
if (action === "added")
{
c.server.update();
}
if (action === "renamed"){
spAriaUtil.sendLiveMessage($scope.m.renameSuccessMsg);
c.server.update();
}
if (action === "deleted"){
spAriaUtil.sendLiveMessage($scope.m.deleteSuccessMsg);
c.server.update();
}
}
$scope.attachmentHandler.getAttachmentList();
$scope.confirmDeleteAttachment = function(attachment, $event) {
$rootScope.$broadcast("dialog.delete_attachment.show", {
parms: {
ok: function() {
$scope.attachmentHandler.deleteAttachment(attachment);
$rootScope.$broadcast("dialog.delete_attachment.close");
},
cancel: function() {
$rootScope.$broadcast("dialog.delete_attachment.close");
},
details: attachment.name
}
})
}
$timeout(function() {
if ($document[0].getElementsByClassName('sc-sticky-item-header').length > 0) {
var titleHeight = $document[0].getElementsByClassName('sc-sticky-item-header')[0].clientHeight;
$scope.stickyHeaderTop = '-' + (titleHeight - 20 - $document[0].getElementsByClassName('sc-cat-item-short-description')[0].clientHeight) + 'px;';
}
});
$scope.$on('sp_loading_indicator', function(e, value) {
$scope.loadingIndicator = value;
});
/* --------------------- */
* Attachments Functions [END] */
/* --------------------- */
Server
< here I know I need to format data._attachmentGUID and other attributes. >
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2020 02:14 AM
did you find any solution for this ? i m also implementing attachment functionality
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2020 02:16 PM
Rajul, yes I did get it working, but I can't take all the credit. Omkar Mone (on the community) helped quite a bit. I turns out that our requirements changed mid-flight and my attachment manager moved away from sc_request to a custom table, also it needed to work with IE 11, so I could not use the glideattachment api.
Here's what it does, let me know if this is the functionality you need and we can take it from there.
- using a SP widget, not a record producer
- paperclip icon onclick allows any number of docs to be attached
- once attached, you may delete or rename before saving base record
- a submit or save on base record secures the attachments
- user can, at a later date, bring up base record and add more doc or remove docs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 07:03 PM
Hi John,
We are also using NowAttachamentHandler. But requirement is that Instead of one paper clip the clients wants two paper clips one to upload regular attachment and other to upload personalattachment. The
function setAttachments(attachments, action) {
$scope.attachments = attachments;
if (action === "added")
{
c.server.update();
}this is working fine for uploading attachments but if I pass another parameter such as personalattachements its not working. Is there any way to differentiate between attachments

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2024 04:55 AM
Hi @John Hughes,
I hope you're well.
You can pass the sys_id attributes of the target record and table to the server with the following script below:
data._attachmentTable = "table_name";//here put your table
data.recordID = "sys_id";// this sys_id is of my instance, put your record or req sys_id so that it will be seen in REQ as well