Mute
October 13, 2016, 12:24pm
#1
frappe.ui.form.on("Expense Claim Detail", "claim_amount", function(frm) {frm.set_value("claim_amount", frm.doc.qte * frm.doc.prix_unitaire); });
I am using the above script to populate the claim amount field by multiplying the two custom fields Qte and prix_unitaire. Unfortnaletly this is not working. Could anyone help me sort this one out please?
1 Like
Sangram
October 13, 2016, 12:54pm
#2
@Mute
script are written on claim_amount
. So it will work only when you change claim_amount
field.
Write it for validate
or refresh
e.g.
frappe.ui.form.on("Expense Claim Detail", "validate", function(frm) {
frm.set_value("claim_amount", (frm.doc.qte * frm.doc.prix_unitaire));
});
It will work when you save the form.
1 Like
Mute
October 13, 2016, 2:24pm
#3
@Sangram Thank you for replying. Is it possible that the script changes the value of claim amount immediately after inputting the values of qte and prix_unitaire?
JoEz
October 13, 2016, 3:32pm
#4
@Mute have a try using:
setTimeout(function () {
frm.set_value("claim_amount", (frm.doc.qte * frm.doc.prix_unitaire));
refresh_field("claim_amount");
}, 300);
Mute
October 13, 2016, 3:48pm
#5
Thank you for replying @JoEz . Unfortunately none of the above solutions are working. The claim_amount field is neither populated automatically or after saving the document. Could anyone help me out please???
JoEz
October 13, 2016, 3:59pm
#6
on which doctype
are the field: qte
and prix_unitaire
? are that custom fields?
Mute
October 13, 2016, 4:31pm
#7
@JoEz Expense Claim Detail is the doctype. qte and prix_unitaire are the custom fields
JoEz
October 14, 2016, 8:30am
#8
@Mute
try:
frappe.ui.form.on("Expense Claim Detail", "validate", function(frm, dt, dn) {
var row = locals[dt][dn];
frappe.model.set_value(dt, dn, "claim_amount", flt(row.qte * row.prix_unitaire));
refresh_field("expenses");
});
put it as Expense Claim custom script
Mute
October 15, 2016, 9:54am
#9
@JoEz not working. @rmehta could you please look into this please?
JoEz
October 15, 2016, 9:56am
#10
where are u putting the script?
Mute
October 15, 2016, 7:40pm
#11
i have created a custom script and tried putting it on the Expense claim
doctype and the Expense Claim detail
doctype @JoEz
Mute
October 17, 2016, 4:19pm
#12
On console i see the error Expected declaration but found ‘*’. Skipped to next declaration.
What could be the meaning of this?
Mute
October 17, 2016, 4:50pm
#13
I finally got it to work using the following script
frappe.ui.form.on(“Expense Claim Detail”, “qty”, function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, “claim_amount”, d.qty * d.prix_unitaire); > });
frappe.ui.form.on(“Expense Claim Detail”, “prix_unitaire”, function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, “claim_amount”, d.qty * d.prix_unitaire);
});`
wale
April 26, 2019, 3:28pm
#15
Just for the sake of future reference, this custom script works only when added to the Parent DocType (at least on V10)
Kind regards,
1 Like