- 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-17-2022 01:37 AM
why not use ACL on sys_attachment?
disableAttachments() hides the attachment and doesn't make it readonly
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 02:07 AM
Hi @Ankur Bawiskar ,
Thank you for your reply, but setting write ACL on sys_attachment affects al the tables, correct?
I would like to make attachment read-only in a specific table only. What kind of ACL script meets this requirement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 02:08 AM
in the ACL of sys_attachment you can give condition for table name so that ACL will only evaluate for your table
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 02:11 AM
@Aki18 try the method which i gave in my below answer
if(current.table_name=="your_table_name")
{
answer=false;
}
else
{
answer= true;
}
Hope this helps
mark the answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 02:17 AM
Hi @Mohith Devatte ,
Thank you for your advice, but I would like to add the condition below. could you please take this in your script?
--> "u_state" is not "2" in current table.