Custom script to pull other fields when one field is updated

Hello, I am trying to keep track of where certain assets are. I have it set up as the “Location”(Link Field) being a zip code and have City, State, and Metropolitan Area as custom data fields that are fetched based on the zip code. When I initially create the asset, the zip code is entered and the other fields are fetching as they should.

HOWEVER, when i transfer this asset to a new zip code(location),
the City, State, and Metropolitan Area fields all remain the same as when the asset was first created. I need those 3 fields to “re-fetch” the new values when the zip code is changed(asset is transferred).

Thanks!

Please refer to this documentation -

1 Like

Thank You akurungadam, we went through several different methods as listed on the documentation and ultimately are at the same spot. This is our latest attempt, which produces no results, but we feel like it should.

frappe.ui.form.on(‘Asset’, ‘location’, {
refresh(frm) {
add_fetch(‘location’, ‘city’, ‘city’);
add_fetch(‘location’, ‘state’, ‘state’);
add_fetch(‘location’, ‘metropolitan_area’, ‘metropolitan_area’);
}
});
frappe.ui.form.on(“Asset”, “location”, function(frm, cdt, cdn){
frappe.call({
“method”: “frappe.client.get_value”,
args: {
doctype: “Location”,
fieldname: “city”,
filters: {
name:[“=”, frm.doc.city]
}
},
callback: function (data) {
console.log(data);
cur_frm.set_value(“city”, data.message.city);
}
});

});

Any advice or suggestions would be greatly appreciated. We are at a standstill until we get it figured out.

for your use case, no custom script needed at all, use the customize form instead
e.g open the pop up window of the newly created field city, input location.city into the Fetch From field like below

We’ve tried, but upon asset transfer, the only thing that updates is the zip (which is the location “name”)