Copy a custom field data into another document

Hi,

I have added an custom field called maintenance_fee into Item table. I want the data of this field to go automatically into the Sales Order Item when I select the item in a Sales Order. I have added a field with the same name (maintenance_fee) in Sales Order Item table, but I am not sure what to do in order to copy the field from the Item table when someone select the item in the Sales Order.

1 Like

Check Not Found

I tried but it doesn’t work. The field being copied is at the Sales Order Item level. Does it matter?

I have tested the method on the Sales Order level where I copy one of the field from Customer table and it works. But the same method doesn’t work on the Item where it can not copy a field from the Item table when I select the Item.

Or is there anywhere I can check why it doesn’t work?

What changes have you done?

I added a custom field called maintenance_fee in Item Form. And I also added a field called maintenance_fee in Sales Order Item Form which is a read only field with the option of item.maintenance_fee. When I create a new Sales order and adding new item into the order, the maintenance_fee is not populated to the item I select.

I am quite sure I did the right way as I have tested this on the sales order level where I am able to populate a field from the other table.

Values do not get automatically copied in the item table. Can you add a GitHub Issue for this. They will be in v5.

Putting item_code.maintenance_fee in options does not work in child table. If you foolow the second method, it will work. That is create Custom Script for Sales Order and write following code:
cur_frm.add_fetch("item_code", "maintenance_fee", "maintenance_fee")

Thanks. Using the custom script method works.

Should I still add a GitHub issue?

please raise the issue

Issue raised in GitHub.

Hi,
I have created a custom data field (po_no) on my Sales Order Form.
then i have created similar custom data field (po_no) on my Sales Invoice Form
How can i fetch the value from my Sales Order field to my Sales invoice field ?
Thx

It should be auto fetched if fieldname are same and no_copy property unchecked for both.

Great , Thanks i actually had missed out one no copy property

1 Like

Based on the above discussion I have created two custom fields item location in Item form and also in “Sales Order Item” form. In addition to this I created a Custom script having this cur_frm.add_fetch(‘item_code’, ‘item_location’, ‘item_location’) and linked it to the Sales Order Item Doc Type. But unable to see the location populated when I add an Item in Sales Order.
My requirement is to add the Location of the Stock item on the Rack and then when the sales order item is generated it should be visible in the table so that based on the sales order list, someone can pick the right item from correct stack instead of them having to know the location of every single item.

@Manu it would be tremendously helpful whether you could add a detailed step-by-step description on how you achieved that here

1 Like

@nabinhait if I am not mistaken the “Fieldname” is generated automatically from the “Label”. Isn’t that so?
So, if that above is true you’d have to name the “Label” in the exact same way as the field you want to grab the data from, right?

Second question … do you have to mark the field that grabs the data from the linked field as ‘read only’?

3rd is rhe field that us created at first automatically the “boss” in the hierarchy of the 2 linked fields?

While generating the Custom Field noticed that the field name is generated from the Lable in lower case with whitespace replaced by _. So in case your lable is “Item Location”, the field name give by the system is item_location.
This is just an observation, some one could confirm this.

Yes, almost as you say

You define a Label ‘My Label’ the database field will automatically be called my_label by ERPNext

My Label —> my_label
My other label —> my_other_label

I think the underscores is a standard way for (SQL?) databases to replace spaces (in field names)

Finally was able to Obtain the Value. Posting the exact steps followed for anyone who needs to do this.

  1. Create the Custom Field “Item Location” under Doc Type Item
  2. Create the Custom Field “Item Location” under Doc Type “Sales Order Item”
  3. Create the Custom Script under doc type “Sales Order” (Note that it has to be created under “Sales Order” was able to reach this conclusion based on the following issue link

Thats all it takes to display the Custom field in the Sales order form based on data entered in Item form.

Does anyone know where I can find this information? This link seems to have been removed.