How to add an attachment functionality in a service portal page?

joanmarisse
Tera Expert

I have this page to record data and I want to add an attachment functionality where users can add attachment in service portal.

Do you have an idea how to do it?

Please advise.

Thanks!

40 REPLIES 40

Thanks for this Sir



Ill check on it.



Best regards,


Joan


Hi Joanmarisse,

i need to create an attachment in my custom portal .

Could you please help me on this , if you achieved this.

 

regards,

Manmath

Unfortunately, I can't load the url


find_real_file.png


Hi Hardik,

After much headache getting file(s) to be passed from client to server side (worked 50% of the time) for using rest call in server script, I came across your widget which does the same client side, without the transient existance issue of the file(s).

I've used your widget with some modification, but the problem I have is that in order to get the file(s) to write through the rest call, I have to pass basic authentication credentials for a user with rest permissions. When doing so, this then logs in to the portal with this user, something I want to avoid. Any thoughts on how to get around this?

 

$scope.uploadFiles = function() {
$scope.fd = new FormData();
$scope.files.forEach(function(file){
$scope.fd.set('files', file);
var request = {
method: 'POST',
url: 'https://<instancename>.service-now.com/api/now/attachment/file?table_name=new_call&table_sys_id='+c.data.sys_id+'&file_name='+file.name,
data: $scope.fd.get('files'),
headers: {
'Content-Type': file.type,
'Accept':'application/json',
'Authorization': 'Basic <base64 encrypted username and password>'
}
};
console.log('HTTP request:',request);

// SEND THE FILES.
$http(request)
.success(function (d) {
// On success code here
})
.error(function (err) {
// On error code here
});

});
}

Not sure. I believe passing authorization in header is mandatory for this: https://docs.servicenow.com/integrate/inbound_rest/reference/r_AttachmentAPI-POST.html