Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Conditional Mandatory Attachment for Catalog Item

nameisnani
Mega Sage

Hi Team,

 

I have a requirement on a Service Catalog Item where an attachment should be mandatory based on a

variable selection.

 

Requirement

 

  • Catalog Item has a Select Box variable: request_type

  • Values:

    • Bank Account Maintenance

    • Scheduler Maintenance

    • Other

  • When request_type = Bank Account Maintenance OR Scheduler Maintenance, an attachment must be mandatory

  • For Other, attachment is not required


    What I Tried

    I implemented a Catalog Client Script (onSubmit) to validate attachments using g_form.getAttachments().



function onSubmit() {

    var requestType = g_form.getValue('request_type');

    // Check only for required options
    if (requestType == 'Bank Account Maintenance' || requestType == 'Scheduler Maintenance') {

        var attachments = g_form.getAttachments();

        if (!attachments || attachments.length === 0) {
            alert('Attachment is mandatory for Bank Account Maintenance or Scheduler Maintenance requests.');
            return false; // Stop submission
        }
    }

    return true;
}

 

 

Not working - any one please help me 

 

2 ACCEPTED SOLUTIONS

Viraj Hudlikar
Tera Sage

Hello @nameisnani 

function onSubmit() {

    var requestType = g_form.getValue('request_type');

    // Check only for required options
    if (requestType == 'Bank Account Maintenance' || requestType == 'Scheduler Maintenance') {

	if (this.document.getElementsByClassName('get-attachment').length == 0)	{    
            alert('Attachment is mandatory for Bank Account Maintenance or Scheduler Maintenance requests.');
            return false; // Stop submission
        }
    }

    return true;
}

 

If my response has helped you, hit the helpful button, and if your concern is solved, do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

View solution in original post

@nameisnani 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

@nameisnani 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

neehas
Tera Expert