This question really applies to all child doctypes, but it was easier to ask using the Sale Order as an example because its well-known.
I added a custom field to both Item and Sale Order Item. The field has the same name in both doctypes.
When I add an Item to the Sale Order, the value from my custom field does not get added to the Sale Order Item.
I read one place where someone said this is supposed to happen automatically if the field names are the same. However, this does not seem to be the case.
Is it possible what you saw was talking about linked docs (i.e., Sales Order → Sales Invoice), which do show this behavior? I’m not aware of anything like this happening with link fields in child docs. (I’m not sure how it’d work either, since child docs can have multiple link fields).
In general, you can do this kind of work with the Fetched From docfield property (accessible via the Customize form tool). Note that this is client side only. If you need to be sure this value is getting set under all circumstances (including API, for example), you’d have to use a server side hook or script.
I went to Customize Form for “Sale Order Item” and edited the custom field “my_field”. In the “Fetch From” box, I wrote “item.my_field”. I saved the changes.
Then I created a new Sale Order and added an item. After I choose the item_code, the standard fields autopopulate but my custom field does not! What is the correct process here?
I think I finally figured it out from finding this Discussion:
In Fetch From, you use the syntax “[source_doctype_primary_index_fieldname].[field_name]”
Personally I think this is way too “magical” looking and non-intuitive for an experienced programmer. Is this even documented anywhere? I’ve spent an immense amount of time trying to figure this out.
The link field is actually called item_code. If you type item_code.my_field, it should work. Is that what you mean by using source_doctype_primary_index.
I can’t think of a more concrete syntax for this field than that, but it any case the whole thing is getting turned into select menus in v14: