Hello community, I am once again, asking for your help.
So I want to fetch a few fields from the database using frappe.db.get_value. Seems simple enough.
This is my whole code:
frappe.ui.form.on('Repairs', {
customer: function(frm) {
var filters = cur_frm.doc.customer;
var customer_info = frappe.db.get_value('Customer', filters, ['address_line1', 'customer_type']);
if (customer_info.customer_type === "individual") {
cur_frm.set_value("address", customer_info.address_line1)
};
}
});
Now the issue with this is, instead of the expected values, I get tons of different stuff I can’t work with. Console.log(customer_info) results in this:
The idea of this code is everytime the customer field is modified, it fills certain information (street in this case) into the address field, but only if it’s an individual customer, not a company.
@emre: This is more than I asked for! But I’ll try this out and see how it works. Thank you.
Although I would like to know why frappe.client.get_value has to be called by another function (frappe.call) rather than being able to be executed itself.
I am not expert on Frappe framework but as i see on example codes and github code investigation i used like this and its worked (if its work don’t touch ).
You said you found this on their github? Guess I need to take a look aswell because data.message is not defined. I don’t see why it needs to be there but if it does then I assume it’s some kind of frappe standard. Thank you.
Also @neerjavkn that makes a lot of sense now and I think it answers the initial question I had.
A big thanks to everyone who helped with this. I chatted with @emre in private a little and we came to the result that the code has to look like this, for anyone interested: