Hi , I have added a custom field _id for User (DocType). But I want to fill that with a random value something like uuid.uuid4() rather than asking for a user input.
Goal : Is to add a random but unique id for each user (System User) that is created
Please point me out where should I refer for this. Since I am unable to locate where actually user registration process takes place inside frappe and there is very little documentation on this subject.
What’s the purpose for this? For User, the name attribute is the primarykey and is also unique (ends up the same as email). If you want to get only users that are System Users, you can filter by user_type (either System User or Website User).
If you want to go ahead with that custom field, be sure to tick “Unique” in the field information. You can hook into the “on_insert” method of User, get a list of the current _id values, and make a new value not in that list. If you make them sequential rather than random, you can get the highest value and just increment by one, which will be faster as the amount of records grows.
@alec_ruizramon1 I am integrating erpnext with an external application which tracks user behaviours , In case I just provide the name attribute and in future the user decides to change his/her information , There will be no way to recognise this change on the external application.
And also the external application is integrated with multiple erpnext instances so using a series will not be possible.
However, regardless of using a series or a random number you will have to check not only if they are unique within their own instance, but also unique against all of the other instances you are using.
How many instances are there? You could have the field use a naming series that is random/related to the company and then it becomes easier!
@alec_ruizramon1 Right now there are 17 instances , each with around 5 users , We are looking for fire and forget integration , manually assigning series would cost time. We are however storing the all the generated random id’s to cross check before issuing new one. There is only one catch how to automatically fill the custom field