Hi everyone,
I am using the following script because I need the field “id_precio” to be narrowed down to one option:
frappe.ui.form.on("Cobro a pacientes", "refresh", function(frm) {
cur_frm.get_field('id_precio').get_query = function(doc) {
return {
filters: [
["Item Price", "item_code", "=", frm.doc.item_code],
["Item Price", "price_list", "=", frm.doc.default_price_list]
]
};
};
});
This works, but now I want to set the value on the field without selecting it from the drop list (because I want the field hidden on the form). Is there a way to set this?

Sorry if I’m not being very clear, any help will be greatly appreciated!
Hey @mroldan get_query will return you more than one option and it will appear in drop-down view only.
you can use frappe.client.get_value and then you can set the value in required field.
I hope this solve your query if you have still have a query please let me know.
Thanks for your answer. I need to get the value of the field that meets the filters conditions, that’s why I used query. “id_precio” has a lot of entries depending on the default price list and the item, so is there a way to use get_value to set the value that meet certain conditions?
Thanks for your suggestion, with this code I’m being able to get the value on the console:
frappe.ui.form.on("Cobro a pacientes", "patient_appointment", function(frm) {
var targetItem = frm.doc.item_code;
var targetPricelist = frm.doc.default_price_list;
frappe.db.get_value('Item Price', {item_code: targetItem, price_list: targetPricelist}, 'price_list_rate')
.then(r => {
let values = r.message;
console.log(values);
});
});
But I can’t find the way to put that value on the field in the form.
How should I replace ‘console.log(values);’ to achieve that?
Worked with
frappe.ui.form.on("Cobro a pacientes", "patient_appointment", function(frm) {
var targetItem = frm.doc.item_code;
var targetPricelist = frm.doc.default_price_list;
frappe.db.get_value('Item Price', {item_code: targetItem, price_list: targetPricelist}, 'price_list_rate')
.then(r => {
let values = r.message;
frm.set_value("precio", values.price_list_rate);
});
});
2 Likes