Good day all
Busy writing a small script to fetch field value from one doc to another.
The one works and the other doesn’t and I suspect its because of form-triggers.
First one works…
Docs involved - Sales Invoice + Customer
Add custom field in “Sales Invoice” called “account_manager”, to be populated from
the “account_manager” field in “Customer”
Added this script in Sales Invoice …
frappe.ui.form.on('Sales Invoice', {
setup(frm) {
cur_frm.add_fetch('customer','account_manager','account_manager')
}
})
So, from the Customer document, I select to add “Sales Invoice” and it populates the
“account_manager” field in SI.
When I do something similar with …
“Job Card” and “Work Order” it doesn’t work.
Add custom field “sales_order” in “Job Card” and wanting to populate it with “sales_order”
from “Work Order”.
frappe.ui.form.on('Job Card', {
refresh(frm) {
cur_frm.add_fetch('work_order','sales_order','sales_order')
}
})
I do understand that there is a slightly different flow when the job-card is created from the
WO.
In fact if I select top right “Create Job Card” then my code works.
If I open the JC that was created from the WO, then it does not populate the “sales order” field.
Also, when I open the JC and I see that the sales_order field has not populated, then , when
I re-select the “work-order” field on the JC, it populates the sales_order field.
So it is clear that I am missing something about the triggers involved. I also noticed that the JC
is ready to be sub-mitted, which means it was already “saved”.
Would appreciate some help on this…
P.S> I tried some of the other triggers …setup, before_load, onload, refresh, onload_post_render.