Expense Claim Form Custom Script


I have few custom fields in Expense Claim Detail.
Now, I want to write a custom script like, when user selects vehicle_type as “Two Wheeler” then rate should become 2.4 below is my code for the same but it is not working can anybody help me in this regard?

frappe.ui.form.on(“Expense Claim”,“vehicle_type”, function(frm, doctype, name) {
for(var idx in frm.doc.items) {
if (frm.doc.items[idx].vehicle_type== “Two Wheeler”)
msgprint(“Two Wheeler”);
frappe.model.set_value(“Expense Claim Detail”, frm.doc.items[idx].name, “rate”, 2.4);



I have tried this code on Expense Claim and Expense Claim Detail but seems like it is not working at all.

Hi Ruchin,

Try below code

frappe.ui.form.on(“Expense Claim Detail”,“vehicle_type”, function(frm, cdt, cdn) {
var d =locals[cdt][cdn]
if(d.vehicle_type == “Two Wheeler”){
frappe.model.set_value(“Expense Claim Detail”, d.name, “rate”, 2.4);

Thanks, Rohit

Hi Rohit,
Thanks a lot, it worked for me.
Just tell me one more that, I want to assign the value of amount as ratekm
I tried it, but its not working.
frappe.model.set_value(“Expense Claim Detail”, d.name, “amount”,rate
Can you tell me the work around for the same?

Ruchin Sharma

refresh the grid after you set the value.

@rmheta can you tell me, how to refresh the grid?

Ruchin Sharma

refresh_field("[grid fieldname]")

It is already there, but anyways my this problem has been resolved by some other way around.

Thanks & Regards
Ruchin Sharma