How to get user id of current user in javascript of frappe?
frappe.session.user is not working
it works from my side, which version do you use?
In javascript it should be frappe.user.name
It is giving error “frappe.user is undefined”, I am using 11.1.25 version of erpnext and 11.1.26 version of frappe
You want frappe.session.user
. This one is the same namespace as is used on the server.
but what should I do if it is not working on my end
do we need to declare something in js file to make it work
It’s a available as a global variable. Type it in the console and you’ll get it.
If you want better help, you need to provide more than one line of context.
Are you trying to get the user in a custom script. You might need to wrap your code around frappe.ready
frappe.ready(function() {
// bind events here
})
After this you can access frappe.session object.
On a general note frappe.session namespace is always available both on the desk as well as website. In case no user is logged in, it returns { user: 'Guest' }
There is weird situation, If I run all these functions in console they work but if I call them through code they does not
try with “user” only in console.log.
Or try console.log(frappe.session) and parse through it to find that where the user_id is stored
Thanks bruh this solved my issue
This solved the issue of not able to access frappe.session.user. Thanks