How to make attachment 'read-only' on Service Portal ("g_form.disableAttachments" not working)?

Aki18
Tera Contributor

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

1 ACCEPTED SOLUTION

@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

View solution in original post

17 REPLIES 17

@Aki18 so you can glide record to that table and add that condition like below

if(current.table_name=="your_table_name")
{
var gr   = new GlideRecord('your_table_name');
gr.addQuery('sys_id',current.table_sys_id);
gr.addQuery('u_state','!=','2');
gr.query();
if(gr.next())
{
	answer=false;
}

else
{
	answer= true;
}
}

 

This script says if its your table and state is not 2 for that particular record hide the delete button for that record 

Hope this helps 

Thanks

Hi @Mohith Devatte ,

I created the delete ACL for itil role as per your instruction, but the user with itil role can still delete the attachment even though the record is "u_state','!=','2'... Any ideas why it's not working?

@Aki18 can you share the screenshot of the acl and the script also please?

 

@Mohith Devatte ,

Please check the followings:

Aki18_0-1668682683252.png

 

if (current.table_name == "custom_table_name") {
    var gr = new GlideRecord('custom_table_name');
    gr.addQuery('sys_id', current.table_sys_id);
    gr.addQuery('u_state', '!=', '2');
    gr.query();
    if (gr.next()) {
        answer = false;
    } else {
        answer = true;
    }
}

@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