Attachment in a catalog item should be mandatory only when certain options are selected. help?

Vaishnavi35
Tera Guru

Hi,

In the catalog item , attachment should be mandatory only when 1 or 2nd choice is selected.

Vaishnavi35_0-1677779567254.png

If anyone can help me with that?

In Catalog item under "Portal settings" we do have an option of attachment mandatory but that for the whole form.

 

Thanks,

Vaishnavi

10 REPLIES 10

Allen Andreas
Administrator
Administrator

Hello,

Please see this article for some assistance: https://www.servicenow.com/community/developer-blog/verify-mandatory-attachments-count-on-catalog-it... 

 

You can add an if check to it as well such as:

if (g_form.getValue('field_name') == 'value_1' || g_form.getValue('field_name') == 'value_2') {
//script here from the link
}

And just change the countrequired to 1, instead of 2.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

The code in the link has a different criteria from mine. It says about the count or number of attachments.

I do not want that.

Just an if conditions that matches the values, "attachments" should be mandatory.

 

Thanks,

Vaishnavi

Hello,

The point of me referencing the script was to give you an example of how to check if there's an attachment or not and make that effective on a condition (such as a field value = x or not). "Attachments" which we have no idea if you have a field named that on your form or not...or if you mean "attachments" in general, would check to see if there was an attachment or not. If not, it blocks the submission of the form and tells them to add an attachment...thus making the attachment mandatory. If you have a field named "attachments" then you can use a simply UI Policy as has been mentioned already. Otherwise, if it's not a field named that, then you'd want to use what I referenced here.

 

I suggest you read over my reply again and also the referenced link. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Anoja
Mega Sage

Hi Vaishnavi,

 

Create the attachment type variable. Make it mandatory for certain options using the ui policy.

 

Thanks,

Anoja