- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 11:26 PM
I created the following Client Script to make attachment 'read-only' when "u_state" is NOT "2".
function onLoad() {
var state = g_form.getValue('u_state');
if (state != '2') {
g_form.disableAttachments();
}
}
It works properly for Classic (Platform) UI, but NOT for Service Portal...
Is this method NOT compatible with SP? If so, is there any alternative way to make attachment 'read-only' based on the condition above?
Best Regards,
Aki
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 03:45 AM
@Aki18 TRY THIS
if (current.table_name == "custom_table_name") {
var gr = new GlideRecord('custom_table_name');
gr.addQuery('sys_id', current.table_sys_id);
gr.addEncodedQuery('u_state!=2');
gr.query();
if (gr.next()) {
answer = false;
} else {
answer = true;
}
}
Also try to put some logs in if loop to check if its going inside for loop
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 11:39 PM
Hi @Aki18 ,
Can you try below script :-
function onLoad() {
var state = g_form.getValue('u_state');
if (state != '2') {
var attachmentButton = top.document.getElementsByTagName("sp-attachment-button");
//console.log(attachmentButton);
attachmentButton[0].parentNode.hidden = true;
}
}
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 01:20 AM
Hi @Gunjan Kiratkar ,
Thank you so much for your reply! Looks like it disabled the "Clip" icon for adding new attachment, but the user can still remove existing attachment by clicking on "x".
Do you have any ideas on how to disable "x" icon as well to prevent users from deleting the attachment?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 01:36 AM
Hi @Aki18 ,
All you need to do is restrict write access to the record when the state is closed. Restricting the edit access, automatically remove the attachment capability.
Update Write ACL on your table to restrict edit access when the state is 2.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 02:12 AM
Hi @Gunjan Kiratkar ,
My requirement is like when "u_state" is NOT "2", make all the field (including attachment) read-only for itil users, but only 1 custom field is allowed to edit as an exception.
How can I achieve this using ACL?
I created