How to upload file from Portal page widget ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2024 11:27 PM
Any OOB widget that can be cloned ?
I have upload option to upload file that must go into attachment table. how to do so in service portal page widget.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 12:36 AM
Hi Snehal,
After cloning the widget did you provide ID for that? Please provide the id in lowercase. and then go to your portal configuration and open with the widget designer. I have cloned of Portal Config Widget and used the upload option from there. Pls refer screenshot attached
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 12:48 AM
Which iD ? Here is what i am trying to do
Upload will insert file in attachment table and script will create a record in contract table.
Later on, I am going to update this new record in contract table as per document uploaded ref
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2024 11:57 PM
I cloned but still the widget isnt appearing on my page. From Portal page designer, I have added the widget.
Also how to save the uploaded files to attachment table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 01:57 AM
What is wrong in below code ? Unable to upload file to attachment table
HTML
<div>
<br> File: <input type="file" id="fileToUpload" onchange="angular.element(this).scope().setFiles(this)">
<br>
<input type="button" ng-click="uploadFiles()" value="Upload"></div>
Server script
(function() {
data.response = '';
var gr = new GlideRecord('sys_attachment'); //input.table
gr.insert();
//how to upload file during insert
})();
Client controller
api.controller=function($scope) {
var c = this;
// CODE FOR sn-record-picker
$scope.tableName = {
name: 'sys_attachment'
};
$scope.$on("field.change", function(evt, parms) {
if (parms.field.name == 'tableName'){
c.data.table = parms.newValue.toString();
c.server.update();
}
});
// CODE FOR input record
$scope.getID = function(rec) {
c.data.record = rec.toString();
c.server.update();
};
// CODE FOR fileupload
/*$scope.files = [];
$scope.setFiles = function(element) {
$scope.$apply(function() {
// Turn the FileList object into an Array
for (var i = 0; i < element.files.length; i++) {
$scope.files.push(element.files[i]);
}
});
};
$scope.removeFiles = function(fname) {
var index = $scope.files.indexOf(fname);
if(index>-1)
$scope.files.splice(index,1);
}; */
$scope.uploadFiles = function() {
alert("Trying to upload file");
$scope.fd = new FormData();
$scope.files.forEach(function(file){
$scope.fd.set('files', file);
var request = {
method: 'POST',
url: 'https://dev23367.service-now.com/api/now/attachment/file?table_name='+c.data.table+'&table_sys_id='+c.data.rec_sysid+'&file_name='+file.name,
data: $scope.fd.get('files'),
headers: {
'Content-Type': file.type,
'Accept':'application/pdf'
}
};
// SEND THE FILES.
$http(request)
.success(function (d) {
alert("Uploaded with success");
})
.error(function (err) {
alert("Error");
});
});
}
};