hide Mandatory checkbox under portal settings using script

ShaziyaS4380655
Tera Contributor

ShaziyaS4380655_0-1761658140617.png

ShaziyaS4380655_2-1761658260189.png

 

  
@Ankur Bawiskar

I have requirement if submitter authoorised selected as No , it should hide attachments , but as it was mandatory on the poratl settings level , how can i hide attachments 

16 REPLIES 16

i have removed mandatory attachment from portal settings and added the on submit client script onto the catalog item , still it is not working , if the submitter is no , then it should make attachment non mandatory and if it yes then attachment should be mandatory and we are using employee portal

@ShaziyaS4380655 

I already shared the code, you just need to add correct variable name and drop down to compare

function onSubmit() {
    //Type appropriate comment here, and begin script below
    try {
        var count = getRPAttachmentCount();
        if (window == null) {
            // portal
            if (count == 0 && g_form.getValue('variableName') == 'yes') {
                alert('You must add attachment before submitting this request.');
                return false;
            }
        }
    } catch (ex) {
        // native view
        var length = getSCAttachmentCount();
        if (length == 0 && g_form.getValue('variableName') == 'yes') {
            alert('You must add attachment before submitting this request.');
            return false;
        }
    }
}

function getRPAttachmentCount() {
    var length;
    try {
        length = angular.element("#sc_cat_item_producer").scope().attachments.length;
    } catch (e) {
        length = -1;
    }
    return length;
}

💡 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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I tried this code but it didn't work 

@ShaziyaS4380655 

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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@ShaziyaS4380655 

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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader