How to set attachment variable (macro) in catalog item as mandatory

Amaresh2
Kilo Contributor

I have an ritm in which i want attachment variable , i made type specification "macro" and called attachment in reference 

but am unable to make it mandatory 

pls help me out in this

 

1 ACCEPTED SOLUTION

Brian Lancaster
Tera Sage

You cannot make the attachment variable mandatory.  If attachments is always mandatory there is a checkbox available in Madrid to when creating the item to make attachments mandatory.  If it is based on conditions for other variables you will need to write an onSubmit client script to prevent from submitting without the attachment.

View solution in original post

3 REPLIES 3

Brian Lancaster
Tera Sage

You cannot make the attachment variable mandatory.  If attachments is always mandatory there is a checkbox available in Madrid to when creating the item to make attachments mandatory.  If it is based on conditions for other variables you will need to write an onSubmit client script to prevent from submitting without the attachment.

Upender Kumar
Mega Sage

Hi,

You can not make variable mandatory but you can check if attachment is attached or not. If there is not attachment you can pop message for attachent.

 

Thanks

AbhishekGardade
Giga Sage

Hello Amaresh,

function onSubmit() {  

    var cat_id = gel('sysparm_item_guid').value;  //or you can use g_form.getUniqueValue();

// you can make call of script include here. as glide record in not recommended in client script

    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()) {  

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

      alert("You must attach a screen shot of the website with the ticket before proceeding.");  

    }

          return false;  

    }

check out this blog :

https://servicenowtips.tumblr.com/post/12902061888/service-catalog-mandatory-attachments 

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade