GlideSysAttachment - Sending as 'undefined'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 06:00 AM
Hey guys
I need help... I'm using the attachmentHandler in the service portal to use the upload file in a custom component. Everything has worked so far, but when I go to view the attached file in the record, a new tab opens with 'undefined'... what am I missing to be able to upload it correctly?
Client controller:
uploader = $element[0].querySelector('#uploader');
$scope.attachmentHandler = new nowAttachmentHandler(function(attachments, evt) {
}, function(error) {
console.log('error', error);
});
angular.element(uploader).on('uploaded-files', function(e) {
$scope.uploadedFiles = e.detail.files;
if (!$scope.uploadedFiles || Object.keys($scope.uploadedFiles).length === 0) {
return;
}
$scope.files = [];
for (var fileId in $scope.uploadedFiles) {
if ($scope.uploadedFiles.hasOwnProperty(fileId)) {
$scope.files.push($scope.uploadedFiles[fileId]);
}
}
$scope.uploadButtonControl();
var files = e.detail.files;
uploader.customAttachmentState = $scope.files
$scope.uidSelected = $scope.files[0]['uid']
$scope.nameSelected = $scope.files[0]['name']
var aux = _.find(uploader.customAttachmentState, function(element) {
return element.uid === $scope.uidSelected
});
});
$timeout(function(){
uploader.defaultAttachmentActions.remove($scope.uidSelected)
}, 19000)
angular.element(uploader).on('remove-file', function(e) {
});
}
$scope.uploadAttachedFiles = function(){
$scope.server
.get({
action: "upload",
docAttach: $scope.files,
recSysId: $scope.data.docCreated
});
};
if (input.action == 'upload') {
var docAttach = input.docAttach;
for (var key in docAttach) {
if (docAttach.hasOwnProperty(key)) {
var file = docAttach[key];
var name = file.name;
var extension = file.extension;
var attachmentTable = 'incident';
var recordSysId = input.recSysId;
var StringUtil = new GlideStringUtil();
var attachment = new GlideSysAttachment();
// Set up inputs
var rec = new GlideRecord(attachmentTable);
rec.get(recordSysId);
var fileName = name;
var contentTypeX = extension;
var content = file.content;
var attachmentSysId = attachment.write(rec, fileName, contentTypeX, content);
console.log('The attachment sys_id is: ' + attachmentSysId);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 07:43 AM
Hi @gcm1
Can you check in attachments table, if any attachment is getting stored. Also could you provide snips/images of testing done.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 10:32 AM - edited 09-14-2023 10:35 AM
Hello @msd93
Thank you for your reply!
Sure, I can see the attachment stored on sys_attachment table (and in fact I notice that the file was being uploaded with content type = pdf only, so I tried to fix that, and I am able to see content type = application/pdf now):
and I can see on the record:
but when I try to open the file, this occurs:
And this is the steps of my testing