Autopopulate a manager field based on user selected in a Businesss application

Community Alums
Not applicable

Hi ,

 

please look at the attachment , the Business Leaders should be auto populated with the Manager of the Business contacts

 

And if the level of the business contact is a manager then he himself should be populated under Business Leader as wellbusiness Leader should be autopopulated on adding business contact.png 

Kindly help with the Request.

1 ACCEPTED SOLUTION

Hello,

 

Please use the below:-

 

Write a Onchange client script on Business contact field with the below code(Remember to replace the businesscontact and businessleader field name with your fieldname)

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var ga = new GlideAjax('getMembers');
    ga.addParam('sysparm_name', 'getMembers');
    ga.addParam('sysparm_internal_service_name', g_form.getValue('businessconatctfieldname'));
    ga.getXML(errorTypeParse);
    function errorTypeParse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue('businessleaderfieldname', answer);
    }
}

 

Then write a script include with name getMembers and have client callable checkbox as true and then use the below code:-

 

var getMembers = Class.create();
getMembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getMembers: function() {
        var arr = [];
        var grp_mem = new GlideRecord('sys_user');
        grp_mem.addEncodedQuery('sys_idIN' + this.getParameter('sysparm_internal_service_name'));
        grp_mem.query();
        while (grp_mem.next()) {
            gs.log('test');
            arr.push(grp_mem.manager.toString());
        }

        return arr.toString();
    },


    type: 'getMembers'
});

 

Please mark my answer as correct based on Impact.

View solution in original post

5 REPLIES 5

Bhagesh chavan
Tera Contributor

Use the onChange Client script on Business Contact field.
- use condition to check if Business contact is Manager

-- if Use populate the same value as Business Leader

else

-- Populate BuisnessContact.Manager to Business leader

 

Saurav11
Kilo Patron
Kilo Patron

hello,

 

Those are list type fields so can there be multiple contacts selected and if yes then do you want to populate managers of all contacts together in the leader field

Community Alums
Not applicable

Yes Saurav, there can multiple contacts selected 

then have to populate managers of all contacts together in the leader field

 

Hello,

 

Please use the below:-

 

Write a Onchange client script on Business contact field with the below code(Remember to replace the businesscontact and businessleader field name with your fieldname)

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var ga = new GlideAjax('getMembers');
    ga.addParam('sysparm_name', 'getMembers');
    ga.addParam('sysparm_internal_service_name', g_form.getValue('businessconatctfieldname'));
    ga.getXML(errorTypeParse);
    function errorTypeParse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue('businessleaderfieldname', answer);
    }
}

 

Then write a script include with name getMembers and have client callable checkbox as true and then use the below code:-

 

var getMembers = Class.create();
getMembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getMembers: function() {
        var arr = [];
        var grp_mem = new GlideRecord('sys_user');
        grp_mem.addEncodedQuery('sys_idIN' + this.getParameter('sysparm_internal_service_name'));
        grp_mem.query();
        while (grp_mem.next()) {
            gs.log('test');
            arr.push(grp_mem.manager.toString());
        }

        return arr.toString();
    },


    type: 'getMembers'
});

 

Please mark my answer as correct based on Impact.