Adding fields to Doctype

Hi, all

I found there are two ways to add fields to Doctype. One is using Custom Field, One is opening the DocType and adding new rows. For the first way will adding records to tabCustom Field table and not change json file, for the second way will change json file and not adding records to tabCustom Field table.

I’d like to know what else difference between these two ways, and which way is better?

Any reply will be appreciated.

1 Like

Hello @Jasmine,
You can use the First way as you say otherwise you can use this way
1.go to the Doctypes List
2. Select Doctype for adding the field.
3.Select on that Doctype and add the field where you want to add.

Sagar Shiragawakar.
New Indictrans Technologies Pvt. Ltd

Hi, @sagar
Thank your reply, the way you provided is my second way :grinning:
Actually I’d like to know what the different between this two ways except I described and which way is better for system maintenance.

My understanding is that it is best practice to:

To avoid conflicts while upgrading ERPNext & Frappe as they evolve in the future,

Add A Custom Field or Fields.

Then go to Customise Form.
Select the Doctype that you want to Customise.
Make any changes to the Doctype like Hide Fields, Set Defaults, Change Order etc etc then update/save.

Then to preserve your custom fields:

From bench command line run:
bench export-fixtures
This will create a .CSV file containing all of your new Custom Fields that you have created to /erpnext/frappe-bench/apps/erpnext/erpnext/fixtures/

Hope This helps


@Jasmine To answer you query please note that there can be 2 types of doctypes:

  1. Doctypes which are part of standard product (like Sales Orders, Item, Customer etc etc)
  2. Doctypes which are made by users as a customization to the erpnext product.

Now if you are wanting to add fields to standard doctypes then you should follow what @System19 said and should not try and mess with standard product since messing would be problematic in case the team makes some changes to that doctype at their end and you would end up with a broken update.

Also you can now add custom fields directly from customize form view and there is no need to go to custom fields page separately.

Now if you have created your own doctype then using custom fields is not going to be the ideal way, in this case you should add the fields directly to the doctype so that the changes are part of the customization.

Please note that when I say “on you own doctype” I have already assumed that you have an app on github to manage your customizations.

1 Like

@adityaduggal @System19 Thank your reply, I’ll try the solution @System19 provided.

Hi, @System19

I tried what you said. It works, but the output under /erpnext/erpnext/fixtures are json files, not the cvs as you said. However this json file include the data in Custom Field. Just wondering if it can create a csv file.

Thats odd. In Ver 6.4
I get a fixtures folder created with a file inside it called custom_field.csv .
It is located at:
If you were to export another doctype with data in it, Say for example the Customer Doctype (via the import option in the Customer Doctype dropdown menu).
Then open that file from your downloads folder in your text editor and you should see a very similar comma separated format.

I have been having the same problem too, here is the solution that worked for me

  1. Use the customize form to change fields in the doctypes( its the safest way to avoid issues)
  2. Click on the export customization button at the top of the customize form ( terminal command suggested by System19 may not work in some cases)
  3. Run $ bench migrate
  4. Refresh and you are good to go