ERPNext Conference 2019* ERPNext.com Blog

How to set key:values (Some user specific values), After successful logged in

customization

#1

Hello,

Is there any way to set some key:values (Some user specific values) After successful logged in, and access it throughout the Application?

So don’t need to call API again and again.

We have a custom App, and want to do that.

Thanks!


#2

Can try

boot_session = "erpnext.startup.boot.boot_session"

https://frappe.io/docs/user/en/guides/basics/hooks


#3

@hetal1110
Can u explain and give example about what do you need to do?

Regards
Bilal


#4

@bghayad,

After successful log in, I want to set some user specific values in Global Variables…that I can use in any doctype throughout the App.

We are using custom App, and have linked user with Department in custom doctype.


#5

Sorry I do not have idea about this :slight_smile:
Where are the global variables? It is just a question because need to know it.

Regards
Bilal


#6

Thanks…From here, I can set values in frappe.boot…

How to set values in frappe.session?


#7

In boot_session set the value using set_user_default(“key1”, “2value2”) and later access it using get_user_default(“key1”)


#8

You can add new file boot.py in your app directory. Then add following code in it

from __future__ import unicode_literals
import frappe
from frappe.utils import cint

def boot_session(bootinfo):
bootinfo.user_tasks = frappe.db.sql_list(""“select distinct tasks from tabUser Tasks”"")

you can access this in js using

frappe.boot.user_tasks