How to disable add/delete attachments on some change forms?

Community Alums
Not applicable

Change tickets are created from record producer. User attaches a word doc and that carries to the change ticket. User must not be able to edit/remove the attached file on change ticket. This is only on some change requests.

How to do this?

1 ACCEPTED SOLUTION

This works quite nice to set the internal can_write_to_record (sys_attachment) to false which hides all of the buttons, so the previous 2 changes are no longer needed.  Add in the HTML field, line 63 just before this line

 <j:if test="${jvar_attachment_disabled == 'true'}" >

<!-- If Firewall Change request, disable adding or removing attachments. -->
   <g:evaluate var="jvar_attachment_disabled" jelly="true">
		var cr = new GlideRecord(jelly.jvar_target_table);
	    cr.addQuery('sys_id', jelly.jvar_target_sys_id);
	    cr.addQuery('short_description', 'CONTAINS', 'Firewall Change');
	    cr.query();
	    cr.next();
	</g:evaluate>

View solution in original post

15 REPLIES 15

Community Alums
Not applicable

Hi Brad,

I had to add two more criteria to enable buttons on Firewall Change. 

 

I added the below scripts, jvar_admin part works. jvar_networkservicesteam does not work. Can you help me here?

<!-- If Admin, enable adding and removing attachments. -->
<g:evaluate var="jvar_admin">
var isAdmin = false;
if(gs.hasRole('admin'))
isAdmin = true;
isAdmin;
</g:evaluate>

<!-- If Network Services Team, enable adding and removing attachments. -->
<g:evaluate var="jvar_networkservicesteam">
var isNetworkServicesTeam = false;
if(gs.getUserID().isMemberOf('Network Services Team'))
isNetworkServicesTeam = true;
isNetworkServicesTeam;
</g:evaluate>

 

<j:if test="${jvar_attachment_disabled == 'true'}">
<j:if test="${jvar_networkservicesteam == 'true' || jvar_admin == 'true'}">
<j:set var="jvar_can_write_to_record" value='true' />
<j:set var="jvar_can_add_attachments" value="true" />
<j:set var="jvar_can_edit_attachments" value="true" />
</j:if>
</j:if>

You definitely need to pass in the group sys_id instead of the name in the isMemberOf function.  Also, the full usage I've always seen follows the format

gs.getUser().getUserByID().isMemberOf('sys_id of group')

Community Alums
Not applicable

Still not working. 

gs.getUser().getUserByID().isMemberOf('sysid') is returning null.

Community Alums
Not applicable

I had to do this gs.getUser().isMemberOf('sys_id') then it worked!

 

Thanks for all your help.

Hi Brad,

I have the similar query and implementing this is not helping since I want the add attachments functionality, but want to only disable the Remove button.

I tried implementing the previous two updates to HTML and Client Script codes but seems like it says that attachments can not be deleted for this change, but once clicked on Ok , it still enables the Remove button and I could remove attachments selected from Change.

Could you please help me on this?

Thanks,
Sumana