How can user without admin role can edit the label in attachment upload in workspace

SomashekarB
Tera Contributor

Hi All,

 

I have requirement where the fulfiller or requester (without admin role) can edit the document label attached to records without changing the extension in workspace. Fulfiller or requester can change the label in native ui but not in workspace.

Can anybody guide me on this?

SomashekarB_0-1737104985388.png

 

2 REPLIES 2

Community Alums
Not applicable

Hi @SomashekarB,

Can you try following method to acheive the requirement:

Use UI Action to Edit the Attachment Label

  1. Create a UI Action on the sys_attachment table (or within a custom table) to provide the "Edit Label" option.
  2. In the UI Action's script, use the same logic as shown in the Script Include above to update the attachment label.
  3. Assign this UI Action to the workspace form or widget, so users with the appropriate role can see it and modify the label.

Script Include:

var AttachmentUtils = Class.create();
AttachmentUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
updateAttachmentLabel: function() {
   var attachmentSysId = this.getParameter('sys_id');
   var newLabel = this.getParameter('new_label');

   var attachment = new GlideRecord('sys_attachment');
   if (attachment.get(attachmentSysId)) {
// Ensure the user has appropriate permissions to modify the attachment
      if (this.hasAccess()) {
attachment.setValue('title', newLabel);
attachment.update();
return 'Label updated successfully';
      } else {
return 'User does not have permission';
      }
}

return 'Attachment not found';
},

 

hasAccess: function() {
// Ensure user has custom role or necessary permissions
return gs.hasRole('attachment_editor');
}
});

 

I don't want to create UI Action as it will add unnecessary UI action which is not allowed in our requirement. Can we use BR and achieve this?