Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

role

suraj 7588
Tera Contributor

how to get role of current logged in user in widget ?

2 REPLIES 2

Samaksh Wani
Giga Sage

Hello @suraj 7588 

 

you need to write a server script and call that variable into HTML.

 

var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', gs.getUserID());
gr.query();
while(gr.next())
{
var role = gr.role; //Will give the sys_id of the roles
}

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

Saurabh Gupta
Kilo Patron

Hi,
You can get the role JSON using below code-

var roleJSON={
    "roleName":[],
"roleSysID":[]

}
var role= new GlideRecord('sys_user_has_role');
role.addQuery('user', gs.getUserID());
role.query();
while(role.next())
{
roleJSON.roleName.push(role.role.name+"")
roleJSON.roleSysID.push(role.role+"");
}
gs.info(JSON.stringify(roleJSON))

Thanks and Regards,

Saurabh Gupta