How to Make one of the related list tab Mandatory

Hanook
Tera Contributor

Screenshot (197).png

 

 

if user click "close case" button then

‘Type’ field is ‘sla’ and the ‘SLA Breach Code’ field is not empty(It'a choice field). If both conditions are met, it allows the form to be submitted. Otherwise, it displays an error message and prevents the form from being submitted. This ensures that the form can only be submitted when the ‘Type’ field is ‘sla’ and the ‘SLA Breach Code’ field is filled
I want code 
Thank You.

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Hanook 

 

https://www.servicenow.com/community/itsm-forum/how-to-make-related-list-as-mandatory/m-p/827850

 

https://www.servicenow.com/community/itsm-forum/how-to-make-one-of-the-related-list-tab-mandatory/td...

 

*************************************************************************************************************
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]

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

Saloni Suthar
Mega Sage
Mega Sage

Please review https://www.servicenow.com/community/itsm-forum/mandatory-related-list/m-p/813518 for the solution. 

If my response helped you, please mark it as correct or helpful.


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @Hanook ,

 

So here your trying to check if the fields are populated before closure of Case, which is a UI action.

 

You can append a code which checks if the fields are populated before closure. If found empty you can return back to current record with an error message. 

 

Please share the UI action code of close case to help you with code. I hope this helps..


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Hanook
Tera Contributor

hello@sohial 

i tried with this code but its not working 

(function executeRule(current, previous /*null when async*/ ) {
 
        var gre = new GlideRecord('sn_customerservice_general_case');
        gre.addQuery('sys_id', current.sys_id);
        gre.query();
        gs.info('u_sla_breach_code Block 1');
        while (gre.next()) {
            var grew = new GlideRecord('task_sla');
            grew.addQuery('task', current.sys_id);
            grew.query();
            gs.info('u_sla_breach_code Block 2');
            while (grew.next()) {
                var slaBreachCode = grew.u_sla_breach_code;
                if (slaBreachCode == '') {
gs.info('u_sla_breach_code Block 3');
                    //g_form.setMandatory('u_sla_breach_code',true);
                    gs.addErrorMessage('Please select the SLA Breach Code for all related SLAs before closing .');
                    //action.setRedictURL(current);
                    current.setAbortAction(true);
                } else {
                    gs.clearErrorMessage();
                }}}
            })(current, previous);

let me know if any changes required
Thank You.