The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Mark Roethof
Tera Patron
Tera Patron

Hi there,

A short article to share gained knowledge about hiding attachments and making attachments mandatory for Catalog Items on the Service Portal. Sharing this because numerous times threads with questions about hiding attachments or making attachments mandatory are coming by.

Pre-Madrid

Pre-Madrid, we could script this thru Catalog Client Scripts. Another option would be to customize the SC Catalog Item widget. Both not great, the Catalog Client Scripts are needed on every Catalog Item you wish to have this functionality on, customizing the SC Catalog Item would mean you would miss updates from patches/upgrades.

For if you are not yet on Madrid and do want to hide attachments or make attachments mandatory. Here is some example scripting.

Hide attachment - onLoad Catalog Client Script

function onLoad() {
	
	var attachmentButton = top.document.getElementsByTagName('sp-attachment-button');
	attachmentButton[0].parentNode.hidden = true;
	
}

 

Mandatory attachment - onSubmit Catalog Client Script

function onSubmit() {
  
	if(this.document.getElementsByClassName('get-attachment').length == 0) {
		g_form.addErrorMessage(getMessage('mandatory_attachment'));

		return false;
	}	
   
}

 

Madrid

With Madrid, some cool and super easy checkboxes are introduced! Checkboxes which can be configured for Catalog Items individually and making scripts like above obsolete.

Madrid checkboxes

find_real_file.png

---

And that's it actually. Hope you like it. If any questions or remarks, let me know!

đź‘Ť
If this post helped you in any way, I would appreciate it if you hit bookmark or mark it as helpful.

Interested in more articles, blogs, videos, and Share Projects on Service Catalog I published?
Service Catalog


Kind regards,
Mark

---

LinkedIn

Comments
Mark Roethof
Tera Patron
Tera Patron

One addition. If you are using a clone of the SC Catalog Item widget [widget-sc-cat-item-v2], then, unfortunately, this will not work. The out-of-the-box SC Catalog Item has been updated with code like:

Body HTML Template

ng-if="c.showAttachments()"

Client Controller

c.showAttachments = function() {
return !$scope.submitted &&
!c.data.sc_cat_item.no_attachments &&
c.data.sc_cat_item.sys_class_name !== "std_change_record_producer";
}

So interested in this new addition from Madrid, update your cloned widget.

Kind regards,
Mark

---

LinkedIn

Brian Lancaster
Giga Sage
Giga Sage

In my case for attachments and I'm sure other a check box with attachment mandatory would not work.  In my current environment attachments are mandatory base on variable choices. For example, on one of my forms it could have anywhere between 0 - 4 attachments mandatory.  It would be nice if they add a drop down with "Always Mandatory" and "Condition Base".  Then if you choose condition based you would choose under what conditions attachments are mandatory.  Although thinking about it that might not necessary meet number of attachments unless there was a filed for that as well. 

Scott Van Den E
Giga Explorer

I need conditional control of attachments based on field values, which I would ordinarily use a catalog client script to configure.

Can you advise if I need the attachments to be visible based on field selection?

Scott Van Den E
Giga Explorer

Brian, did you find any way to achieve your desired results?

Feddy
Tera Guru

Hide attachment check box is inactivated by system in our instance, what would be the issue.
I couldnt see the field in list or form even after making it active.

amol_joshi
Tera Contributor

How to achieve mandatory attachment before submitting a workspace form?

Version history
Last update:
‎04-21-2019 08:02 AM
Updated by: