Make Attachment mandatory on Catalog Item based on field

Dazler
Mega Sage

Hi, I am needing to create a catalog client script to make an attachment mandatory based on a field selection on a Catalog Item.  I  know that there is a feature in the Madrid version to select "make attachment mandatory" but I do not need it for the entire catalog item, but only when a certain field is selected.  

This is what I have so far, but I am having trouble.  Any help will be truly appreciated.

function onSubmit() {

if(g_form.getValue('bulk_request') == 'true'){

var cat_id = gel('sysparm_item_guid').value;

var gr = new GlideRecord("sys_attachment");

gr.addQuery("table_name", "sc_cart_item");

gr.addQuery("table_sys_id", cat_id);

gr.query();
	
if (!gr.next()) {

alert("You must attach a file to submit.");

return false;

}

}

}

 

5 REPLIES 5

Ashley Snyder1
Giga Guru

I've used the script(s) in this blog with a lot of success. The script is for both the platform UI and the Service Portal and you can adjust it to check for variable values as needed. Just make sure you put the UI Script and JS Theme in, then you can create as many Catalog Client Scripts as needed for consistency:

https://www.servicenowelite.com/blog/2017/5/12/service-portal-require-attachments

If my response was helpful, please mark as Helpful and consider setting the reply as the Correct Answer if it best answered your question, thank you!