Try ERPNext Buy Support Partners Foundation

How to add custom field using custom script?

I would like to insert a custom field of “Data” type into the current doc using custom script. How can I achieve this? Is there any documentation for this?

Use customize form and you can add column. After adding you have update column in hooks.py. then export fixtures. Once you pull code into production server you need migrate. Go to this link https://docs.erpnext.com/docs/user/manual/en/customize-erpnext/custom-field

2 Likes

I referred to the link you gave but my requirement is little different. I would like to insert a custom field into a form based on parameters that may differ from time to time So the Field’s Label, name or type can’t be decided early on and after using the data entered on those fields I wouldn’t need them anymore. So I am looking for a way to insert the custom field using JS in the front end? Is there any API that is exposed to the outside just like the frappe’s Dialog API?

To handle this, you’d want to write some client-side JavaScript. Write JS to create the field(s) you need, including their labels and types. Those labels could definitely change, based on the values of other inputs. (pseudocode: IF (field ABC==1), THEN custom field's label = "quantity", ELSE label = "weight").

After the user populates them, take additional actions. For example:

  • Use these fields to modify the values of later, database-driven fields.
  • Store these values…somewhere? You’d have to implement your own storage technique in the browser. Transmit the data to a 3rd party. Or perhaps store them in generic SQL columns in ERPNext.

That’s exactly my requirement but what function should I call to insert a field into the current form? Are there any examples available?

Is it not possible to add temporary custom field using JS in frappe?

Fields in ERPNext are 1-to-1 representations of database columns, and likewise it’s not really intended that they be temporary. It might be possible to hack the html to create a pseudo-field from the client side, but a much more robust solution in my opinion for realtime display-only data would be an HTML field that you can populate with content at runtime.