Custom button to show pop up to upload attachments in portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 07:54 AM
Hi,
I have a requirement to create a button on portal on click of which 2 things should happen -
1. A new record should be created in Document (dms_document) table, and current record should be updated with inserted record. (This is happening)
2. On click of the button, a pop up window should be displayed to upload attachment and the attachment should get attached to current record. (Need help with this)
Script -
HTML Template -
<div style="float:right; margin-bottom:10px;">
<button type="button" ng-click="clickUpload()" ng-if="data.showBtnDoc=='yes'">Upload Document</button>
</div>
Server script -
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
var id = $sp.getParameter('sys_id');
var getVal = new GlideRecord('x_eyit2_lcm_tool_fog_fof');
getVal.get(id);
var docVal = getVal.document;
if (docVal == '') {
data.showBtnDoc = 'yes';
} else {
data.showBtnDoc = 'no';
}
if (input && input.checkRec == 'yes') {
var name = getVal.name;
var num = getVal.number;
var doc = new GlideRecord('dms_document');
doc.initialize();
doc.name = num + '-' + name;
var sysID = doc.insert();
data.new_id = sysID;
getVal.document = sysID;
getVal.update();
}
})();
Client Controller -
api.controller=function($scope) {
/* widget controller */
var c = this;
$scope.clickUpload = function() {
c.data.checkRec = 'yes';
c.server.update().then(function(response) {
//spUtil.update($scope);
c.data.checkRec = '';
});
location.reload(true);
};
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2022 01:22 AM
Hey,
there is an add attachment widget created by
Generally speaking uploading an attachment with a custom action is not as easy as it may seem. However, there is an API (which is also used in the widget i linked) that allows you to upload an attachment to any table/record you may need.
Regards
Fabian