# Frappe Model Set Value Child Table Problem

Hi all,
My problem is a rather peculiar one. Let’s say I have a doctype name Parent If. Within this document are two fields:

1. A child table called Child IF
2. An int field called Total

In the child table are 4 fields:

1. tip
2. tip_2
3. tip_3
4. tipster

Now, I have a very simple condition set to work on the child table. Here’s my code: (i’ll explain my logic below)

``````frappe.ui.form.on("Child IF", {
tipster:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total1 = 0;
frm.doc.child_if.forEach(function(d) {
if(d.tip == "Low") {
if (d.tip_2 == "Low" ){
frappe.model.set_value(d.doctype, d.name, "tip_3", "Low 2");
}
total1 += d.tipster;
}
});
frm.set_value("total", total1);
refresh_field("total");
},
tipster_remove:function(frm, cdt, cdn){
var d = locals[cdt][cdn];
var total = 0;
frm.doc.child_if.forEach(function(d) {
if(d.tip == "Low") {
if (d.tip_2 == "Low" ){
frappe.model.set_value(d.doctype, d.name, "tip_3", "Low 2");
}
total1 += d.tipster;
}
});
frm.set_value("total", total1);
refresh_field("total");
}
});
``````

What I want to do is check if both tip and tip_2 are equal to “Low”. I want to set the value for tip_3 as “Low 2” if both tip and tip_2 are “Low”. This does not work for some reason. However if tip equals “Low”, the script adds the value of tipster to the total and later to the total field in the parent doctype implying that the if condition is working fine. The only issue is with setting the value for tip_3 based on the conditions. Any help is appreciated.

Found the solution, might be useful to you guys so im posting it. Dont bother with js side scripting, write a server script for this. The code for my use case is as follows:

``````for item in doc.child_if:
if item.tip == "Low":
if item.tip_2 == "Low":
item.tip_3 = "Low 2"
``````