Catalog Item make attachments NON-mandatory based on variable

xiaix
Tera Guru

There are a bazillion questions/posts on how to make an attachment mandatory based on a variable, but non (that I can find) to do the opposite.

I have a catalog item with this checked:

xiaix_0-1669644285381.png

I always need an attachment on this particular item.... unless there is 1 checkbox checked.  If that checkbox is checked, then I need to make attachments NON-mandatory.

 

Anyone out there know how to accomplish this?

1 ACCEPTED SOLUTION

I need that checkbox checked.  I'll just chalk it up to the fact that this cannot be done, keeping that checkbox checked.  It appears there is no way at all possible to keep it checked and make the form not need an attachment based on a variable.

View solution in original post

6 REPLIES 6

Mohith Devatte
Tera Sage
Tera Sage

Hello @xiaix ,

this article is going to solve your problem.Follow the steps correctly and then you will be able to achieve it .

 

https://www.servicenow.com/community/developer-articles/possible-ways-for-making-an-attachment-manda...

 

1) Add a UI script 

2)Add a JS theme to your portal on which your catalog item is there

3)Write an client script - Use the script given in third step of the article (onsubmit) and add your if logic to that script like below to check your variable value

 

 

 

function onSubmit() {
//Works in non-portal ui
try {
var attachments = document.getElementById('header_attachment_list_label');
if ((attachments.style.visibility == 'hidden' || attachments.style.display == 'none'  ) && g_form.getValue('your_checkbox_name') ==false) {
alert('You must attach the completed form before submitting this request.');
return false;
}
}
//For Service Portal
catch(e) {
var count = getSCAttachmentCount();
if(count <= 0 && g_form.getValue('your_checkbox_name') ==false) {
alert('You must attach the completed form before submitting this request.');
return false;
}
}
}

 

 

Hope this helps

Mark my answer correct if this helps you 

Thanks

@Mohith DevatteI challenge you to read my post.  I mean really read it. 

@xiaix i read it by the way and you have to uncheck that check box and do it through script because if you  use that check box we cant make it non mandatory so through script you need to handle it and thats why i proposed the above solution in the article 

I need that checkbox checked.  I'll just chalk it up to the fact that this cannot be done, keeping that checkbox checked.  It appears there is no way at all possible to keep it checked and make the form not need an attachment based on a variable.