Auto-populate Manager and Additional Manager Fields Based on Configuration Item's Support Group

LokeshwarRV
Tera Contributor

I am working on a ServiceNow form that includes a Multi-Row Variable Set (MRVS) with fields for Configuration Item, Manager, and Additional Manager. When a user selects a Configuration Item, I need the Manager and Additional Manager fields to automatically populate with values based on the support group of the selected Configuration Item.

this is my script include

getCISupportGroupManager: function() {

        var configItem = this.getParameter('sysparm_config_item');

        var managerDetails = {};

        var gr = new GlideRecord('cmdb_ci_server');

        gr.addQuery('sys_id', configItem);

        gr.query();

        if (gr.next()) {

            var supportGroup = gr.support_group;

            gs.log("[SupportGroup]", + supportGroup);

            var grSupport = new GlideRecord('sys_user_group');

            grSupport.addQuery('name', supportGroup);

            grSupport.query();

            if (grSupport.next()) {

           

                managerDetails.manager = grSupport.manager;

                managerDetails.additionalManager = grSupport.additional_manager;

            }

        }

        return JSON.stringify(managerDetails);

    }

and this is my clientscript

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == '') {

        return;

    }

    var ga = new GlideAjax('QuestCatalogItemHelper');

    ga.addParam('sysparm_name', 'getCISupportGroupManager');

    ga.addParam('sysparm_config_item', newValue);

    alert(newValue);

    ga.getXMLAnswer(function(response) {

        var managerDetails = JSON.parse(response);

        g_form.setValue('manager_name', managerDetails.manager); // Replace 'manager' with your actual field name

        g_form.setValue('additional_manager_name', managerDetails.additionalManager); // Replace 'additional_manager' with your actual field name

    });

    //Type appropriate comment here, and begin script below

 

}

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@LokeshwarRV 

update as this

I hope your script include is client callable and you are writing the correct script for correct variable within that MRVS

Script Include: You should query with sys_id and not name

getCISupportGroupManager: function() {

    var configItem = this.getParameter('sysparm_config_item');

    var managerDetails = {};

    var gr = new GlideRecord('cmdb_ci_server');

    gr.addQuery('sys_id', configItem);

    gr.query();

    if (gr.next()) {

        var supportGroup = gr.support_group;

        gs.log("[SupportGroup]", +supportGroup);

        var grSupport = new GlideRecord('sys_user_group');

        grSupport.addQuery('sys_id', supportGroup);

        grSupport.query();

        if (grSupport.next()) {



            managerDetails.manager = grSupport.manager.toString();

            managerDetails.additionalManager = grSupport.additional_manager.toString();

        }

    }

    return JSON.stringify(managerDetails);

}

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

@LokeshwarRV 

Hope you are doing good.

Did my reply answer your question?

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

3 REPLIES 3

OlaN
Giga Sage
Giga Sage

Hi,

If your MRVS always would have the manager and additional manager populated from the CI selected, then what's the point of having these values at inputs at all?

You could retrieve them at a later stage using dotwalking. I don't see a use case for including them in the form if they always should be autopopulated.

Ankur Bawiskar
Tera Patron
Tera Patron

@LokeshwarRV 

update as this

I hope your script include is client callable and you are writing the correct script for correct variable within that MRVS

Script Include: You should query with sys_id and not name

getCISupportGroupManager: function() {

    var configItem = this.getParameter('sysparm_config_item');

    var managerDetails = {};

    var gr = new GlideRecord('cmdb_ci_server');

    gr.addQuery('sys_id', configItem);

    gr.query();

    if (gr.next()) {

        var supportGroup = gr.support_group;

        gs.log("[SupportGroup]", +supportGroup);

        var grSupport = new GlideRecord('sys_user_group');

        grSupport.addQuery('sys_id', supportGroup);

        grSupport.query();

        if (grSupport.next()) {



            managerDetails.manager = grSupport.manager.toString();

            managerDetails.additionalManager = grSupport.additional_manager.toString();

        }

    }

    return JSON.stringify(managerDetails);

}

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

@LokeshwarRV 

Hope you are doing good.

Did my reply answer your question?

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