Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to make assignment group mandatory in HR case based on hr services?

Apaul
Tera Contributor

How to make assignment group mandatory in HR case based on hr services? I tried using ui policy or CS, didn't work. Help me please

6 REPLIES 6

Shraddha Kadam
Giga Sage

Hello @Apaul ,

 

Please try with the below script or share your script. This is worked for me -

 

Business Rule -

1. Create Display Business rule on HR Case table -

2. Write below script -

(function executeRule(current, previous) {

    var hrServiceNames = [];
    var grHRService = new GlideRecord('sn_hr_core_service'); // Query the HR Service table

    // Define your encoded query
    var encodedQuery = 'active=true^name=401(k) Retirement Plan Enrollment Inquiry^ORname=Beneficiaries Inquiry'; 

    grHRService.addEncodedQuery(encodedQuery);
    grHRService.query();

    while (grHRService.next()) {
        hrServiceNames.push(grHRService.getValue('sys_id')); // Get the display name of each service
    }
    g_scratchpad.hrServiceNames = hrServiceNames.join(',');

    gs.addInfoMessage('Business Rule: Populated hrServiceNames with: ' + g_scratchpad.onboardingHrServiceNames);

})(current, previous);

 

Client Script -

1. Create onLoad client script o HR Case table

2. Make inherited checkbox True

3. Write below script 

function onLoad() {
	alert("Line 2"+ g_form.getValue('hr_service'));
    if (g_scratchpad.hrServiceNames) {
        var services = g_scratchpad.hrServiceNames.split(',');
        alert('HR Services: ' + services.join(', '));

        var currentServiceDisplayName = g_form.getValue('hr_service');
        if (services.indexOf(currentServiceDisplayName) > -1) {
            g_form.setMandatory('assignment_group', true);
        }

    } 
}

 

This should work.

 

Thank you.

If my response was helpful, please mark it as correct and helpful.
Thank you.

AndersBGS
Tera Patron
Tera Patron

Hi @Apaul ,

 

Please share the UI Policy that you have tried to create - alternative, you can write a client script or a scripted UI Policy based on if this is only for specific services.

 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/