Add custom fields to Users?

I’d like to create a custom field for Users that will store their Twilio phone number.

It will be used for a custom Dialog I am building to send SMS messages via Twilio from Lead/Contact forms.

The problem is that apparently ERPNext doesn’t allow “Core” Doctypes to be customized.

What’s the best way to add a custom field for users?

1 Like

Hi @oguruma:

Some options:

  1. Edit the doctype instead customize it. (Note that your change will be gone with further updates).
  2. Create a custom app. Use fixtures to include Custom field for User Doctype
    Frappe Core DocTypes can't be customized in Version 11 - #29 by lasalesi
  3. Create a secondary doctype, linked to user. Put your new field there.

Hope this helps.

1 Like

Thanks, I went with the 2nd option.

This is how I did it.
Add this to ur hooks.py:

fixtures = [    
    # Adding custom fields to User doctype
    {
        "doctype": "Custom Field",
        "filters": [
            ["dt", "=", "User"]
        ]
    }
]

I already had a fixtures directory generated, if you don’t have one you can simply create one in the same directory as your hooks.py called “fixtures”. In there I created a file called “custom_fields.json” with the following content:

[
    {
      "doctype": "Custom Field",
      "name": "User-signature",  
      "dt": "User",
      "fieldname": "signature",
      "fieldtype": "Signature",
      "insert_after": "username",
      "label": "Signature"
    },
    {
      "doctype": "Custom Field",
      "name": "User-job_title",  
      "dt": "User",
      "fieldname": "job_title",
      "fieldtype": "Data",
      "insert_after": "mobile_no",
      "label": "Job Title"
    }
  ]
  

(Use “insert_after” to insert your custom field after a core doctype field.)

2 Likes

Can you mention the version of frappe you are using ?

2 Likes

Version 15 for sure, I am not sure about the exact versions but these are the one I use right now:

ERPNext: v15.40.0

Frappe Framework: v15.46.0