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

Dr Atul G- LNG
Tera Patron
Tera Patron

You need to create the catalog policy for this and make the necessary logic changes.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Ankur Bawiskar
Tera Patron
Tera Patron

@ShaziyaS4380655 

then don't make the attachment mandatory in portal settings.

Use onSubmit catalog client script and see the variable value and then make attachment mandatory

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

@Ankur Bawiskar 
But it should be mandatory on  catalog item , but when sumitter field is selcted with no add attachments should get hided , hence preventing the user from submitting the request

 

@ShaziyaS4380655 

you cannot hide that bottom attachment thing.

the only way is the approach I shared.

That will work for you.

💡 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