
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2018 01:57 AM
Hi. I have this script :
$scope.attachFile = function(files, $event) {
var e = $event.currentTarget;
console.dir("value e : " + e.value);
if (e) {
e.value = '';
}
console.log("files[0]");
console.dir(files[0]);
console.log("snAttachmentHandler before");
console.dir(snAttachmentHandler);
var sna = snAttachmentHandler.create('myUserTable', $scope.data.elementSysId);
console.log("snAttachmentHandler after");
console.dir(sna);
sna.uploadAttachment(files[0]).then(function (response) {
console.log("sna.uploadAttachment");
console.dir(sna);
console.log("response");
console.dir(response);
var fName = response.file_name;
console.log("fname");
console.log(fName);
if (fName.indexOf('inp_') != 0) {
fName = "inp_" + fName;
snAttachmentHandler.renameAttachment(response.sys_id, fName).then(function (response) {
var nah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, function () { });
nah.setParams('myUserTable', $scope.data.elementSysId, 1024 * 1024 * 24 /*24MB*/);
function setAttachments(attachments, action) {
$scope.attachments = attachments;
$scope.data.attachmentList = attachments;
}
$scope.attachmentHandler.getAttachmentList();
});
}
});
};
But i get an error, always the same : TypeError: Cannot read property 'indexOf' of undefined
I use the same script in another widget, and everythings work fine... Somebody can help?
[EDIT]
This is the console log result :
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2019 07:55 AM
I found the problem... I didn't have enough right on my table to allow the user to insert an attachment. So I've add the right WRITE to my table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2018 02:15 AM
Hi,
Not sure, but try printing the value of fName and value fetched by fName.indexOf('inp_').
'inp_' is either not defined or is not available in current scope.
Regards,
Ajay

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2018 02:22 AM
Thanks for your answer.
but the problem is : the variable "response" after uploadAttachment is empty, so the fname is empty too.
"inp_" is just a suffit I checked to know if it's already in the file name to not create a file with : inp_inp_myfile.pdf
It's look like the uploadAttachment dosn't work at all
The array : "files[0]" is correct with the file attached to it.
Any ideas?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2018 02:30 AM
Hi
Have you tried printing console.log(files[0])?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2018 02:32 AM
Hi,
Yes, same result than the "console.dir(files[0])". 😉 I've edited my quesiton with more information and many console.log.