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

Ankur Bawiskar
Tera Patron
Tera Patron

@Aki18 

why not use ACL on sys_attachment?

disableAttachments() hides the attachment and doesn't make it readonly

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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?

@Aki18 

in the ACL of sys_attachment you can give condition for table name so that ACL will only evaluate for your table

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@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

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.