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

@Mohith Devatte ,

The user with itil role can still delete the attachment...

I set gs.info in the if loop and got the system log generated, so I think it's going inside the loop.

Please help me with troubleshooting it.

 

if (current.table_name == "sn_customerservice_notification_list") {
    var gr = new GlideRecord('sn_customerservice_notification_list');
    gr.addQuery('sys_id', current.table_sys_id);
    gr.addEncodedQuery('u_revision_approval!=2');
    gr.query();
    if (gr.next()) {
        gs.info("test")
        answer = false;
    } else {
        answer = true;
    }
}

 

@Aki18 then i think it should be other acls which might be giving the access check for the acls with read or delete operations where it might be giving the access which might be over riding your ACL 

Thanks

Mohith Devatte
Tera Sage
Tera Sage

hello @Aki18 ,

if you want to make it read only which means it should be visible but should not be able to delete the attachment then what you can do is write a delete operation ACL on sys_attachment script with the script like below 

if(current.table_name=="your_table_name")
{
	answer=false;
}
else
{
	answer= true;
}

Refer below screenshot :

Screenshot 2022-11-17 at 15.13.46.png

Hope this helps 

Mark my answer as correct if this helps you

Thanks

Mohith