Hi, I was trying to retrieve records from another doctype by the record name. Im not sure whether i have any syntax error here.
what i did here is i want to get location_name and group from my Fixed Asset doctype by filtering the record name, i had comfirm that the field name is correct and i suspect that i code wrongly at the filter part from frappe.call method. i had also check that targetAsset do able to store the value of frm.doc.fixed_asset using window alert
but i get undefined from my r.message, i use alert(r.message.name) to check at the callback function
Did you mean if i use get_list i can get multiple records?
for example if i filter by location_name and group_name at get_list,
in my target doctype i have 3 records by this filter,
then my “r” from callback function ( r ) will contains 3 records
so if i use $.each to loop it i can go through every record that i want?
@KAH_MENG_Long
Correct. If you have 3 records, you will get an array with r.message[0] (=1. Record), r.message[1] (=2. Record) and r.message[2] (=3.record)
Lets say i want to validate my booking time whether my fixed asset is available to book or not,
I have to go through all the records of my Asset Booking doctype to validate the date and I code like this,
but it does not work, it just let me save the record with any input of datetime.
frappe.ui.form.on("Asset Booking", "validate", function(frm) {
var targetAsset = frm.doc.fixed_asset;
frappe.call({
method: 'frappe.client.get_list',
args: {
'doctype': 'Asset Booking',
'filters': { 'fixed_asset': targetAsset },
'fieldname': [
'start_datetime',
'end_datetime'
]
},
callback: function(r) {
for (i=0; i < r.message.lenght; i++) {
if (frm.doc.start_datetime >= r.message[i].start_datetime && frm.doc.start_datetime <= r.message[i].end_datetime){
frappe.msgprint("The asset had been booked at the moment, please choose other date.");
frappe.validated = false;
}
if (frm.doc.end_datetime <= frm.doc.start_datetime){
frappe.msgprint("Wrong enddatetime.");
frappe.validated = false;
}
if (frm.doc.end_datetime >=r.message[i].start_datetime && frm.doc.end_datetime <= r.message[i].end_datetime) {
frappe.msgprint("Wrong enddatetime which is in between people's booking.");
frappe.validated = false;
}
}
}
});
})