Ammended: I have a set_query on shipping_address in Purchase Order which used to work all the time. After upgrading to the latest version it works once in awhile and doesnt most of the time. Any idea why?
Just to share, I think there is absolutely no way to control and therefore determine which AJAX call gets returned reliably. Therefore, although not the best design, one way to defeat this is to have the query run every time the field is clicked on. Again, not the best in design but if you have such a requirement, this is what you can do:
frappe.ui.form.on("Purchase Order", "refresh", function(frm) {
cur_frm.fields_dict.shipping_address_name.$input.on("click", function() {
//Show all Shipping Addresses even those not linked to the selected Customer
cur_frm.set_query("shipping_address_name", function() {
return {
"filters": {
"docstatus": "0"
}
};
});
});
});
We had this script in production on some systems and it started to produce errors. Our new workaround is to use two triggers: onlod_post_render and refresh. This way we can overwrite existing queries in all possible loading scenarios: refreshing, reloading, navigating between records, visiting the URL directly.