- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2018 12:25 AM
Hi All,
I need to get the display name of all group's of which the current logged in user is a member. Although , i am able to print the group's sys_id, but the groups display name isnt coming. Any help, please
function onLoad() {
//Type appropriate comment here, and begin script below
var currentuser=g_user.userID;
var obj= new GlideRecord('sys_user_grmember');
obj.addQuery('user',currentuser);
obj.query();
while(obj.next())
{
var grpname=obj.group.getDisplayValue(); // display name is not coming here
alert(' logged in user is member of : '+grpname);
}
}
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2018 11:07 PM
This is the not a correct way to get the group details.. you should avoid glide record in client script. ("Best Practice")
i would suggest, mention glide record part in script include and call your function in your client script by using Glide Ajax.
here you go..
Script include:
var group = Class.create();
group.prototype = Object.extendsObject(AbstractAjaxProcessor, {
hello: function()
{
groupArr=[];
var json = new JSON();
var grmember = new GlideRecord('sys_user_grmember');
grmember.addQuery('user',gs.getUserID());
grmember.query();
while(grmember.next()){
groupArr.push(grmember.group.getDisplayValue());
}
var data = json.encode(groupArr);
return data;
},
type: 'group'
});
Client Script:
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('group');
ga.addParam('sysparm_name', 'hello');
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var s = answer.evalJSON(); //Transform the JSON string to an object
for( var i=0 ; i < s.length ; i++) {
alert(s[i]);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2018 12:07 AM
Hi,
It is advised to use display Business Rule. We should avoid GlideRecord API in client script API.
Use display business rule and store data in g_scratchpad variable and access this on client side.
BR code
current.g_scratchpad.variable=values;
Client Side
onLoad Script
alert(g_form.g_scratchpad.variable)
Thanks