Chandu Telu
Tera Guru

Hi Naved,

 

Quick Point : User can be part of multiple group 

 

 checkGroup: function() {
        var currentUser = gs.getUser();

        if (currentUser.isMemberOf("Group Name")) {

            var gr = new GlideRecord('sys_user');

            gr.addActiveQuery('active=true'); // Filter to return active records.

            gr.query();

            while (gr.next()) {

                return gr.group.name; // Do you have Field called Group in User Table if yes return

return gr.group+"";
            }
        }
    }

Client Script : Onload:

   var ga = new GlideAjax('Display_Organization_fALU_fNokia');
    ga.addParam('sysparm_name', 'checkGroup');
    ga.getXML(groupName);


    function groupName(response) {

        var answer = response.responseXML.documentElement.getAttribute("answer");

alert(answer) - let me know what is in the alert
        g_form.setValue('organization',answer);

    }

Thanks
Chandu Telu
Please Mark Correct/helpful, if applicable,

Hi Naveed,

Follow Up - is your requirement is completed with my answer. Please mark answer as correct it will use for other community members if not let us know your issue so we can help you 

Thanks
Chandu Telu
Please Mark Correct/helpful, if applicable,

Jaspal Singh
Mega Patron

Hi Naved,

What for case if user is part of multiple groups? You still want this to happen only for particular group as in line:       if (currentUser.isMemberOf("Group Name")) {

Not applicable

Hello @Naved Shaikh 

If you are using catalog item form and setting currently logged in users single group in "Organization" reference field, then you can directly use below code in default value - 

 javascript: gs.getUser().getMyGroups();

find_real_file.png

 

In other cases, kindly use Chandu's code.

 

Thanks
Akshay Kangankar

Ankur Bawiskar
Tera Patron

@Naved Shaikh 

Can you explain what's your business requirement?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader