Display error message when, removing attachment is not allowed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 12:03 AM
Hello all,
I needed help in a requirement which involves showing an error message on INC table record when someone tries to remove an attachment on it and is not allowed to do so.
I tried a "Delete" BR on the "sys_attachment" table, but the error message does not appear on INC table (form view).
I guess it has something to do with "gs" object used in gs.errorMessage.
So wanted to know if it is possible to do this.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 12:28 AM
Hi @Aman Thakur ,
1. You can try alternative ways like create an ACL that stops from deletion of attachment.
2. Try to Hide the X or delete button on Incident table to disallow attachment deletion on incident table.
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 12:53 AM
Hi @Aman Thakur ,
You can use "g_form.disableAttachments();" to hide the paper icon based on your access.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 02:22 AM
Thankyou @Runjay Patel & @Sohail Khilji , for your replies.
The Scenario: Users can remove only those attachments on INC record that were added by a particular group (let's say Group 1). So, only those attachments can be removed/deleted which were added by Group 1 members.
But based on your replies, can it be concluded that this cannot be achieved using BR and gs.errorMessage() method?
Because I could see the error messages on "sys_attachment" list view when I tried removing/deleting an attachment directly from Attachment table.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 04:28 AM
Hi @Aman Thakur ,
On that case you can use ajax call to check the user belong to group or not. if dont then use "g_form.disableAttachments();"
1. Create onload client script and use below code.
var ga = new GlideAjax('UserUtils');
ga.addParam('sysparm_name', 'checkGroupUser');
ga.addParam('sysparm_caller_sys_id', group_name);
ga.getXML(hideAttachment);
function hideAttachment(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer=='false') {
g_form.disableAttachments();
}
2. create script include and use below code.
var UserUtils = Class.create();
UserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkGroupUser: function() {
var group= this.getParameter('sysparm_group_sys_id');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',group);
gr.addQuery('user',gs.getUserID());
if(gr.next())
return true;
else
return false;
},
type: 'UserUtils'
});
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------