Any function to refresh a link field in child table (to further refresh fetch fields)

Hey again, (and thank you again)

I’ve been using a button (refresh_times) for easy testing of the functions, and still to no avail.

frappe.ui.form.on("Sales Invoice", "refresh_times", function(frm) {
  frm.refresh_field("timesheets")
  frm.refresh_field("time_sheet")
});

Both the name of the child doctype “timesheets” and link field “time_sheet” are refreshed because I’m a bit hopeless in these respects :wink:

Go through this post, this might help you.

https://discuss.frappe.io/t/how-to-fetch-child-tables/12348

1 Like

I’ve been browsing around, also while trying several combinations of script to have this active, but still no luck. Is anybody aware of any methods to retrigger a link field to get fetched fields to work?

Me too looking for some pointers on the same problem. I have a child table that fetches record (item_code & qty) from Delivery Note.

//fetch child table from Delivery Note Item to Hamriyah Customs Item (item_code & qty)
frappe.ui.form.on(“Hamriyah Customs”, “delivery_note”, function(frm) {
frappe.model.with_doc(“Delivery Note”, frm.doc.delivery_note, function() {
var tabletransfer= frappe.model.get_doc(“Delivery Note”, frm.doc.delivery_note)
$.each(tabletransfer.items, function(index, row){
d = frm.add_child(“items”);
d.item_code = row.item_code;
d.qty = row.qty;
cur_frm.refresh_field(“items”);
})
});
});

I also need net_weight and other custom field from Doctype Item which isn’t readily available in DN,so i fetch them using custom script below

cur_frm.add_fetch(“item_code”,“net_weight”,“unit_weight”)
cur_frm.add_fetch(“item_code”,“description_ar”,“description”)

which unfortunately works ONLY when item_code is manually re-selected /re-triggered. In this case, the item_code is fetched programmatically.

i have attempted fetching via a button (get_info) with add_fetch but didn’t work either.

frappe.ui.form.on(“Hamriyah Customs Item”,“get_info”, function(frm){
cur_frm.add_fetch(“item_code”,“net_weight”,“unit_weight”);
cur_frm.add_fetch(“item_code”,“description_ar”,“description”);
refresh_field(“items”);
});

Error:

return fn(*args, **newargs)
TypeError: runserverobj() takes at least 1 argument (1 given)

1 Like

Have you had any success with finding a solution for refreshing fetches?

no luck yet, using reselect as workaround…

Is that done through script? Or are you going line by line like me and re-triggering each link field?

yea old school by mouse pointer

Hi guys!
I was able to refresh a dependent query by setting value to field using frappe.model.set_value rather than row.fieldname = value

It works like this:
frappe.model.set_value(row.doctype, row.name, fieldname, value);

Let me know if it works for you.

2 Likes

That sounds like good news! Im still uncertain of how to apply it, would you mind sharing the script that you used this function in?

frappe.ui.form.on("Journal Entry", "voucher_type", function(frm, cdt, cdn) {
		if((!(frm.doc.accounts || []).length) || ((frm.doc.accounts || []).length==1 && !frm.doc.accounts[0].account)) {
		  if(frm.doc.voucher_type=="GTA Expense Entry") {			
		    frappe.model.clear_table(frm.doc, "accounts");
		    var list_of_accounts = [
		    	"Freight Outward",
		    	"Creditors",
		    	"GTA Service Tax 14%",
		    	"GTA Krishi Kalyan Cess 0.5%",
		    	"GTA Swachh Bharat Cess 0.5%"
		    ];

	        $.each(list_of_accounts, function(index, value) {
					var row = frappe.model.add_child(frm.doc, "Journal Entry Account", "accounts");
					frappe.model.set_value(row.doctype, row.name, "account", value);
			});
			frm.refresh_field("accounts");
		  }
		}
});
2 Likes

When all else fails, frm.refresh() usually works. But it refreshes everything (parent doc and all) instead of just the childtables.

1 Like

I found that using origin_doc.origin_field as an option in the custom field triggers the fetch properly except for longtext. Is there any way to overcome this, or is it a bug when it comes to framework?

For reference, the field was within “Sales Invoice Timesheet” and fetched additional information required, probably on a refresh trigger, but “save” has done the job

Also (barely) visible is the timesheet note field, which is a longtext field that has the same option that doesn’t work

Grr… It was “Text Editor” in the timesheet, and “Long Text” in my custom field that it was fetched to. Switching to “Text Editor” fixed it

1 Like

Is there any accepted solution? I’m stuck in the same boat

Last two replies should help. Also, save to refresh if you don’t have a refresh line in your script

hi @superlack, would you mind sharing? I’m trying to do the same but I don’t even know how to start.
I can create custom fields in “Sales Invoice Timesheet” but that’s about it :slight_smile: When I try to fetch data using cur_frm.add_fetch from “Timesheet Detail” I get nothing…and I think that cur_frm.add_fetch will not work in this case…

Hey there, make sure that you’re putting the script in the parent doc (sales invoice), and that you’re saving, or triggering a refresh to make it function.

Also, I haven’t tested in a while, but this instead of using the custom script fetch method, this alternative might have been what I used to make it work:

@superlack
hey Thanks , but your alternate method only works if the field type is data .
Any idea how to make it work if both the destination and source fields are LINKS ?
infact cant seem to fetch anything if its a Link field.
any more brilliant ideas?

Thanks

@superlack frm.refresh_field(‘table name’);