How do you make attachments not mandatory for a CheckBox variable?

Community Alums
Not applicable

Hi,

I have a variable (type = CheckBox) that when it is checked, I do not want the attachments on the SC item to be mandatory, otherwise if the CheckBox is not checked, it should be mandatory. I can't figure out how to achieve this. Can someone provide the best practice solution/suggestion please?

Thanks!

1 ACCEPTED SOLUTION

Ashley Snyder1
Giga Guru

Are you using this on the platform, service portal, or both? At this time, the ootb 'Attachment Mandatory' feature is a one or nothing kind of function, meaning there is no condition to check a variable, hopefully they'll put this in, in a future release.  I've used the following blog with success on multiple instances, and it works for both the Service Portal and platform.

Make sure you add the UI Script and JS theme, and then you can create multiple catalog client scripts utilizing this code for consistency:

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

Here's an example I used in the past to check a variable, just make sure the UI Script and JS theme is in place before trying to use the Catalog Client Script:

var type = g_form.getValue('uvar_typeOfRequest');
    try { //Works in non-portal ui

        if (type =='infochange') {
            var attachments = document.getElementById('header_attachment_list_label');
            if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {

                g_form.addErrorMessage("Please attach the Informational Change Template to this request");

                return false;
            }
        }

    } catch(e) { //For Service Portal

        var count = getSCAttachmentCount();

        if(count <= 0 && type == 'infochange') {

            g_form.addErrorMessage("Please attach the Informational Change Template to this request");

            return false;

        }

    }

 

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!

View solution in original post

5 REPLIES 5

d_cammack
Tera Guru

Do you have attachments mandatory through a catalog client script?  If so, you can try getting the variable value and using it on a condition to run the script:

var chk = g_form.getValue('[checkbox variable]');
if (chk == false){
  // attachment mandatory script
}

Community Alums
Not applicable

I have Mandatory Attachment enabled from the portal settings of the catalog item. However, I don't want the attachment to be mandatory when I click on CheckBox variable. Can I achieve that from a Catalog UI Policy?find_real_file.png

Tony Villarrea1
Tera Contributor

Hi Preet,

 

I would utilize an advanced UI Policy. Set your filter requirements when checkbox = true.

Under script - execute if true, use the following code.

function onCondition() {
g_form.disableAttachments();

 

If my answer helped you, Kindly mark it as correct and helpful. 😉 

Community Alums
Not applicable

Tried that but it's not working.find_real_file.png