getMyGroups() function is giving sys_id rather than name of the group.

SNOW32
Giga Expert

Hello Everyone,

Hope you all are doing good !!

I wrote a "before" business rule to insert group name of logged in user, who  submitting the form.

So, all records which belongs to their logged in user's group.

Code of business rule is given below:

var groupnames = getMyGroups();
gs.info("Group name is : " + groupnames);
 
When I am checking in System Log ,,I can only see sys_id.
How to retrieve name of the group rather than sys_id.
I tried with gs.info("Group name is : " + groupnames,getDisplayValue()); as well as ("Group name is : " + groupnames,getDisplayValue('name'));
But it showing result as "undefined". 
Please help with it .
Thanks,
Anu
 
5 REPLIES 5

Chuck Tomasi
Tera Patron

Hi,

That's what getMyGroups is supposed to do. it returns an array of sys_ids and is commonly used in filters.

If you want an array of names you can write your own version of the same script.

 

function getMyGroupNames() {

    var answer = [];
    var sugrm = new GlideRecord('sys_user_grmember');
    sugrm.addQuery('user', gs.getUserID());
    sugrm.query();

    while (sugrm.next()) {
        answer.push(sugrm.group.getDisplayValue());
    }

    return answer;
}

SNOW32
Giga Expert

Hi Chuck,

I need to add groups in a field i.e.  a reference field . I am adding your code in the before business rule. But I am getting error.Could you please let me know , how to add group value to the field.

find_real_file.png

find_real_file.png

Thanks

Anu

Hi Anu,

Time to back up and ask the basic question... "What are you trying to do?" In other words, what's the underlying business requirement behind this business rule. I can offer the best technical solution when I understand the problem that we're trying to solve. Please help me understand and perhaps we can work through this with the script (or another solution) to your problem.

Thank you

SNOW32
Giga Expert

Hi Chuck,

I have created a table (screenshot given below). And the form will submitted by members of 2 groups. Group member of both group is submitting the form. So, I need to insert the group in a database...of the current group member who is submitting the form.

Group name field is a reference field of group table. I don't need to insert in a form. Just I need to insert group name in a database. So that, I tried for business rule which is not working .

So, please help me to get it.

find_real_file.png

Thanks,

Anu