- Drop Down 3 values
- Based on value selected in above drop down list , i need to populate other field(Link Type) based on if the value is not allocated in DB.
Hi there, not sure if this will help, but this is one sample script I’m using to fetch values from my DB using AJAX calls, you’ll need to adjust yours accordingly:
Client Script:
frappe.ui.form.on('Project', {
activity_id: function(frm){
//console.log(frm)
let activity_id = frm.doc.activity_id;
if(activity_id.length === 10){
frappe.call({
method: "erpnext.calls.get_activity",
args: {activity_id: activity_id}
}).done((r) => {
//console.log(r)
// Activity Details
frm.doc.start_date = r.message[0].activity_start_date
frm.doc.end_date = r.message[0].activity_end_date
// Refresh all fields
Object.keys(frm.doc).forEach(function (item) {
refresh_field(item)
});
//console.log("Finished.")
})
}
}
});
On the server, under apps/erpnext I created calls.py and the function get_activity(arg) which will query the DB according to the docs here: Database API
In my case above I’m passing the activity_id as arg for the py function and processing it (r.message[0] is the response).
Edit:
Just adding on to the backend file:
/calls.py
import frappe
@frappe.whitelist()
def get_activity(activity_id):
return frappe.db.sql(f"SELECT * FROM <your_table> WHERE <condition>;", as_dict=True)
1 Like