g_form.disableAttachments(); doesn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2020 11:31 AM
Our team is working in New York and want to hide the Attachment button on a record producer if you don't have a certain role. We have a catalog client script onLoad that has:
g_form.disableAttachments();
if you do not have the "admin" role. However, that does absolutely nothing. We are developing in a scoped application and have read that disableAttachments only works in global. Is this true? We've recreated the catalog client script in global and it still does nothing. Is this a bug or are we doing something wrong?
As a workaround, we're using this:
function onLoad() {
var attachmentButton = top.document.getElementsByTagName("sp-attachment-button");
//console.log(attachmentButton);
attachmentButton[0].parentNode.hidden = true;
}
However, it's not 100% ideal because the footer that the button is in is still visible and when the page loads, you see the attachment button for a split second before it disappears. Any thoughts or suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2020 11:41 AM
Hi yundlu316,
Could you try an onLoad client script something like this:
if (g_user.hasRole('admin'))
return;
g_form.disableAttachments();
'OR'
You could also look at ACLs on the sys_attachment table, but that could be a bit more global thank you want for just catalog items.
Please do mark correct and helpful based on impact.
Regards,
Arvind
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2020 04:44 PM
Any reason why this shouldn't be done via ACLs?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2020 06:46 PM
Hi,
Did you try adding alert in the onload client script?
It should work. I don't think it is disabled for scoped app
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2020 06:24 AM
hi yes, we added an alert and it fires correctly, but disableAttachment() does not hide the paperclip icon. This is our onLoad code:
function onLoad() {
//Type appropriate comment here, and begin script below
var roleCheckEmployee = g_user.hasRole('sn_hr_sp.hrsp_employee');
var roleCheckAdmin = g_user.hasRole('admin');
if ((roleCheckEmployee == true) && (roleCheckAdmin == false)){
g_form.disableAttachments();
//var attachmentButton=top.document.getElementsByTagName('sp-attachment-button');
//attachmentButton[0].parentNode.hidden=true;
}
}