Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Hide Opened_For from the Assigned To Choice Selection for HR Case

Hari7
Kilo Guru

Hide Opened_For from the Assigned To Choice Selection for HR Case

 

Wrote onLoad Client Script but it didnt work.

function onLoad() {
    // Get the 'Opened For' user's sys_id
    var openedForUserSysId = g_form.getValue('opened_for');

    // Get the HR Service value
    var hrServiceValue = g_form.getValue('hr_service');

    // Get the Assignment Group
    var assignmentGroup = g_form.getValue('assignment_group');

    // Check if the HR Service and Assignment Group match the specified values
    if (hrServiceValue == '2bd814771ba38dd0d1a59938b04bcbc8' && assignmentGroup == 'b25370019f22120047a2d126c42e705c') {
        // Set the reference qualifier to exclude the 'Opened For' user
        var referenceQualifier = 'sys_id!=' + openedForUserSysId;

        // Apply the reference qualifier to the 'assigned_to' field
        g_form.setReferenceQualifier('assigned_to', referenceQualifier);

        // Check if the 'assigned_to' field is pre-populated with the 'Opened For' user and clear it if necessary
        var assignedToValue = g_form.getValue('assigned_to');
        if (assignedToValue == openedForUserSysId) {
            // Clear the 'assigned_to' field if it contains the 'Opened For' user
            g_form.setValue('assigned_to', '');
        }
    }
}

 

Can you please let me know if there is anything wrong in the code or any other method to achieve this logic. 

 

1 REPLY 1

jcmings
ServiceNow Employee

@Hari7 

Here's a post where someone solved for the same thing. It looks like you'll need a script include and an Advanced Reference Qualifier on the field. Here is a link to the docs on reference qualifiers.

 

If you're trying to do this on a catalog item, reference this post.