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

Thank you so much. That worked really well. 

Can you also help me with the Adding Attachments?

In the same UI Page, I am trying to modify the validateAttachment() function that takes care of adding attachments. The problem with this is, it shows the attachment popup and I try to attach, it does not allow me. Then, I try to close the attachment popup, then it gives me an alert "Close before uploding attachments?"

How to handle this?

function validateAttachment() {
	var form = $('sys_attachment');
	var fileFields = form.select('.attachmentRow');
	
	if(attachmentParentTable == 'change_request'){
		var chg = new GlideRecord(attachmentParentTable);
		chg.addQuery('sys_id', attachmentParentSysId);
		chg.addQuery('short_description', 'CONTAINS', 'Firewall Change');
		chg.query();
		if(chg.next()){
			attachButton.disabled = "true";
			alert('You cannot add attachments after Firewall Change Request is created');
			return false;
		}
		else{
			for (var i = 0; i < fileFields.size(); i++) {
				if (fileFields[i] && fileFields[i].value != "") {
					setAttachButton(""); //disable
					$('please_wait').style.display = "";
					return true;
				}
			}
			alert("${JS:gs.getMessage('Choose a file to attach')}");
			return false;
		}		
	}
	else {
		for (var i = 0; i < fileFields.size(); i++) {
			if (fileFields[i] && fileFields[i].value != "") {
				setAttachButton(""); //disable
				$('please_wait').style.display = "";
				return true;
			}
		}
		alert("${JS:gs.getMessage('Choose a file to attach')}");
		return false;	
	}
}

So you want to prohibit adding a new attachment under the same conditions (Firewall Change request)?

Community Alums
Not applicable

Exactly. I already tried that script. 

I am getting this alert

find_real_file.png

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>

Community Alums
Not applicable

Thank you so much Brad. That worked awesome!