ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

How to get logged in user's role

customization

#1

Hi,

I would like to get the logged in users role

what i have done so far is

class CourseFeedback(Document):
def validate(self):
if frappe.session.user==‘Administrator’:
frappe.throw((“Hello admin”))
frappe.throw(
(frappe.session.role))

but i get empty popup

please help me


How to use get_query to get User containing a role?
#2

for .py
frappe.get_roles(frappe.session.user)
for .js
user_role


#3

@jsukrut
thanks it worked awsome

i have another doubt like this way can i get full name of current user


#4

@shahid_khan021
use frappe.db.get_value()
eg.
frappe.db.get_value(“User”,{“name”:manager},“full_name”)


#5

@shahid_khan021
frappe.db.get_value(“User”,{“name”:frappe.session.user},“full_name”)


#6

@jsukrut thanks again friend


#7

@jsukrut, the return of “frappe.db.get_value(“User”,{“name”:frappe.session.user},“full_name”)” is an object. Do you know how to parse the object to get the full name as a string? Thanks!


#8

I think it will return ‘unicode’ .like <type ‘unicode’>

If you have object then you can access properties with ‘.’ (member operator)

eg.
user_doc = frappe.get_doc(“User”,name)
print user_doc.first_name
print user_doc.last_name

for typecast

str(user_doc.last_name)


#10

How about getting the password of the session?


#11

you can’t access password through get_doc. What is your use case?


#12