How to make attachment mandatory on portal while approving

Prathamesh Cha1
Tera Contributor

Hi Team,

 

I want to make attachment mandator on portal while approving for Specific catalog item.

PrathameshCha1_0-1749537766821.png

 

Thanks,

BR

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Prathamesh Cha1 

why would approver add file during approval?

you can use before update business rule on sysapproval_approver table and query that target record to know if file is attached or not

OR

You can clone the OOTB widget on portal, make necessary changes and then add this newly cloned widget again to portal page

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Prathamesh Cha1 

why would approver add file during approval?

you can use before update business rule on sysapproval_approver table and query that target record to know if file is attached or not

OR

You can clone the OOTB widget on portal, make necessary changes and then add this newly cloned widget again to portal page

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Deepak Shaerma
Kilo Sage

Hi @Prathamesh Cha1 

you need to do the changes on the Approve widget inside the Approval form page, after cloned the OOTB.
if you need to put validation from the Approve Button from instance default view, modify the UI action

// Assume this runs in a UI Action on a record that must have an attachment

var gr = current; // current record (e.g., change_request)

var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_sys_id', gr.sys_id);
attachmentGR.addQuery('table_name', 'sysapproval_approver');
attachmentGR.query();

if (!attachmentGR.hasNext()) {
    gs.addErrorMessage('Approval is not allowed without at least one attachment.');
    action.setRedirectURL(current); // redirect back to record
    answer = false; // stop the UI Action
} else {
    current.state = 'approved'
current.update();
}

Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma