Grab a value from another doctype, which was in another doctype defined in a field

OK, I’ll try your method. But, while waiting, I tried another method like this:

  1. Create a custom field named ‘coi’ which linked to DocType Country
  2. create this function:
frappe.ui.form.on('Customer', {
	coi: function(frm) {
	    if(frm.doc.coi) {
            frappe.db.get_value('Country', frm.doc.coi, "code").then(res => {
                let x = res.message
                var countryCode = x.code;
	        });
                console.log(countryCode);
	    }
	}
});

But now the countryCode variable is undefined. Did i do wrong?