Doc Type Field creation Through Code Level

I want to create a field in the existing doctype through code level, rather than using UI.
Any suggestions to do the above requirement?

Thanks in Advance

you can change the json file inside the doctype folder and then do bench build and restart . but I don’t recommend it .

@bahaou Thanks for your response.

If that’s not a recommended way, my use case was below scenario

We have two different sites with multitenancy mode. Both sites have the same doctype and fields. Admin adds a new field in the doctype (Site A), we need to do the same changes in Site B doctype through any scripts or something. without doing any manual work.

How do we achieve the use case?

Thanks in Advance

you can refer the guide below

Use create_custom_fields function.

Example: https://github.com/frappe/ecommerce_integrations/blob/f02cc4e51e83139d00db554c09df5d6668e6efb8/ecommerce_integrations/shopify/doctype/shopify_setting/shopify_setting.py#L114

1 Like