I want to take the country code value from the “primary_customer_address” field in DocType “Customer”. The process is that everytime i created a new customer, when clicking Save button, I want to be able to get the country code (IN, ID, US, etc) from the customer primary address and store it in a variable.
I know that the data flow is from Field “Code” in DocType “Country”, which is selected from the field “Country” in DocType “Address”, which is selected in field “customer_primary_address” in DocType “Customer”. I have no idea how get the value from the database that deep.
I’ve tried db.get_value, but it seems to not working at all.
The thing is, if i just use console.log(r.message.code);, it works and returns the country code into console. But if I try to send it to another variable, it just doesn’t work. Even trying this:
var countryCode = frappe.db.get_value('Country', frm.doc.coi, 'code');
which is how the docs write about, is still not working. If I check the console, countryCode is just an object of Promise, which is definitely not how it is in the docs/tutorial: https://frappeframework.com/docs/user/en/api/database.