How can we get User full name from session??
I need this too. You found a solution?
EDIT: Is there a way to prefill a doctype with values, which we can not get by Customize Form?
I tried to add the full_name of the current user to a custom field, but I couldn’t get it work by Customize Form. By JavaScript/jQuery, I would need a seperate AJAX request, just to get the full user name, as following:
#client side in mycustomdoctype.js
frappe.call({
method: "mycustomapp.utils.get_full_user_name",
args: {"user": frappe.session.user },
callback: function(r) {
if(r.message) {
frm.set_value("current_user", r.message)
}
}
});
#server side
@frappe.whitelist()
def get_full_user_name(user=None):
p = frappe.db.get_value("User", user, "full_name")
return p
As this may be useful for someone, I like to post it here, but as I wrote, it it a separate AJAX request, for a very basic information.
Is there a way to solve it server side?
EDIT: For a client side solution, use sione solution below:
(we are still searching for a server side solution, without the need of a separate AJAX request)
This is what I used to get the user fullname
var Current_User = user;
frappe.call({
method:"frappe.client.get",
args: {
doctype:"User",
filters: {'email': Current_User
},
},
callback: function(r) {
cur_frm.set_value("User_Full_Name", r.message["full_name"]);
}
})
Good solution! Better than mine. It reduces the need of custom server side scription.
To get the logged in User’s fullname you can use the frappe.user.full_name(uid)
in custom script directly no need to use the frappe.call to fetch the user_info as it is already available.
Thanks,
Makarand
Thanks a lot…much easier solution
Thank you. Where does uid come from?
Reference Error: uid is not defined
Excuse me:
i need to add custom filed in quotation
name it
Quotation By
and this filed take its data from the current login user
For example if the login user is
abc@abc.com
so when this user make a quotation
the filed will automatically take its name
as the one who made this quotation
how can i achieve this ?
best regards .
I would find this useful too
Its already there u can check the owner field in the db.
Regards
also create a int field called valdone so you don’t keep overwriting every time you save
frappe.ui.form.on("Quotation",{
validate: function(frm) {
if(cur_frm.doc.valdone !== 1 ){
frappe.call({
method: "frappe.client.get",
args: {
doctype: "User",
filters: {"email":user}
},
callback: function(r) {
frm.set_value("quotation_by", r.message.full_name);
frm.set_value("valdone", 1);
}
})
}
}
});
Hi @makarand_b
This solution returns the value “You” instead of the actual name of the user!
Kind regards,
For fetching logged in user’s ID, try
frappe.session.user
Hi @jaichavan
This works fine for user ID though I was also hoping to get the actual Full Name
Thanks a lot
For seeking Full Name, try:
frappe.session.user_fullname
Works for me: