How to make attachment mandatory based on condition for record producer in service portal?

Srinivas Goud K
Tera Contributor

I need to make attachment is mandatory based on condition. There is a check box in the form If I select that one then it should become attachment mandatory how to implement that please help me out.

I have used below Script but it is become mandatory for entire form I want it for particular variable only

Please check attachment 

function onSubmit() {

    var cat_id = g_form.getValue('sysparm_item_guid');
    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("Attachment is mandatory if you select Preapproved");
        return false;
    }
}

1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

Hi,

I would suggest to use the attachment type variable for attaching the attachment and us UI policy to make it mandatory based on your required conditions.

You can achieve it with out scripting and It is recomanded as a best practices.

 

Thanks,

Sagar Pagar

The world works with ServiceNow

View solution in original post

6 REPLIES 6

Sagar Pagar
Tera Patron

Hi,

I would suggest to use the attachment type variable for attaching the attachment and us UI policy to make it mandatory based on your required conditions.

You can achieve it with out scripting and It is recomanded as a best practices.

 

Thanks,

Sagar Pagar

The world works with ServiceNow

To do UI policy the attachment type variable is not showing

Hi @Srinivas Goud Kadali,

You can select the attachment type variable in Catalog UI Policy. I have tried and use in some of catalog items and record producers.

find_real_file.png

 

Thanks,

Sagar Pagar

The world works with ServiceNow

This attachment variable is not working currently, If you attach any thing but it does not attach in the ticket. hence we can not use that varibal.