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.

Fetch the manager of the selected assignment group and displays the manager's name as a field messag

Jyoti Ranjan Se
Tera Contributor

Hi everyone,

I wrote this script but still its not working can you please help me on this.

Script----

 

(function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue == '') {
        return;
    }
 // Fetch the assignment group record
    g_form.getReference('assignment_group', function(group) {
        if (group && group.manager) {
            // Fetch the manager record
            g_form.getReference(group.manager, function(manager) {
                if (manager && manager.name) {
                    // Display the manager's name as a field message
                    g_form.showFieldMsg('assignment_group', 'Change Manager: ' + manager.name, 'info');
                }
            });
        } else {
            // Clear the field message if no manager is found
            g_form.showFieldMsg('assignment_group', 'No manager found for this group', 'info');
        }
    });
})(g_form.getControl('assignment_group'), g_form.getValue('assignment_group'), g_form.getValue('assignment_group'), g_form.isLoading(), g_form.isTemplate());


Regards
Jyoti
1 REPLY 1

Uncle Rob
Kilo Patron

g_form can only work with fields that are on the form.