ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

How to get child table value from another child table


#1
  1. I have three child table, child table 1, child table 2 and child table 3.
  2. In child table 1, and child table 2, i have supervisor score column.
  3. now i want to sum up supervisor score of table 1 and 2 and display in another child table. Sum of score of child table 1 should display in row 1 (Rating on Actual Work Performend ) and sum of score in child table 2 should display in row 2 (Rating on achievement of competencies) in child table 3.

i have drown in screen short. Please help me

i used below code but not working:

frappe.ui.form.on(“Appraisal”, “validate”, function(frm, cdn, cdt){
var c = locals[cdt][cdn];
var weighted_score = 0;
c.weighted_score = flt(doc.achievement_rating);
c.weighted_score = flt(doc.total_supervisor);

});


#2

Please help me, anyone


#3

@namgyal
in place of var c =locals[cdt][cdn],you have to use child table name like this
var c=locals[cdt][cdn].childTable3FieldName
c[0].weighted_score = flt(doc.achievement_rating);
c[0].weighted_score = flt(doc.total_supervisor);
cur_frm.refresh_fields(childtable3Fieldname)


#4

@ROHAN_JAIN1, thanks for your reply but its not working .

i used below code:

frappe.ui.form.on(“Appraisal”, “rating”, function(frm,cdt,cdn){
var c = locals[cdt][cdn].rating;
c[0].weighted_score = flt(doc.achievement_rating);
c[0].weighted_score = flt(doc.total_supervisor);
cur_frm.refresh_field(rating);
});

below is ChildTable3Field link:

please can you help me.


#5

@namgyal
what error you are getting which executing the code?


#6

@ROHAN_JAIN1, i have change code little bit and it work. But when i create new form, its giving page dis-order.

frappe.ui.form.on(“Appraisal”, “refresh”, function(frm,cdt,cdn){
var c = locals[cdt][cdn].rating;
c[0].weighted_score = cur_frm.doc.achievement_rating;
c[1].weighted_score = cur_frm.doc.total_supervisor;
cur_frm.refresh_field(“rating”);
});

please can you help me, what the prolem


#7

@ROHAN_JAIN1, when i remove “refresh” than i can create new form but not working below 2 line code to fetching value ( c[0].weighted_score = cur_frm.doc.achievement_rating;
c[1].weighted_score = cur_frm.doc.total_supervisor;
)

Or there is other code to replace above 2 line code. when i remove above 2 line code i can create new form but fetching data not working

And when i put “refresh”, its working below code to fetch value for save form but when i create new form, page come with dis-order which i screen short above.

code:
frappe.ui.form.on(“Appraisal”, “refresh”, function(frm,cdt,cdn){
var c = locals[cdt][cdn].rating;
c[0].weighted_score = cur_frm.doc.achievement_rating;
c[1].weighted_score = cur_frm.doc.total_supervisor;
cur_frm.refresh_field(“rating”);
});

can you help me please


#8

in browser console it show below screen short:


#9

@namgyal try below code
frappe.ui.form.on(“Appraisal”, “refresh”, function(frm,cdt,cdn){
var c = locals[cdt][cdn].rating;
if(cur_frm.doc.achievement_rating != undefined && cur_frm.doc.total_supervisor != undefined){
c[0].weighted_score = cur_frm.doc.achievement_rating;
c[1].weighted_score = cur_frm.doc.total_supervisor;
cur_frm.refresh_field(“rating”);
}
});

you are getting the error because of refresh event is called always.


#10

@namgyal you can set the value of c[0].weighted_score and c[1].weighted_score on change of achievement_rating and total_supervisor. respectively
like this:

frappe.ui.form.on(“Appraisal”, {

achievement_rating : function(frm,cdt,cdn){

	if(locals[cdt][cdn].achievement_rating != undefined ){
		var c = locals[cdt][cdn].rating;
		c[0].weighted_score = cur_frm.doc.achievement_rating;
		cur_frm.refresh_field("rating");
	}
},

total_supervisor:function(frm,cdt,cdn){

	if(locals[cdt][cdn].total_supervisor != undefined ){
		var c = locals[cdt][cdn].rating;
		c[1].weighted_score = cur_frm.doc.total_supervisor;
		cur_frm.refresh_field("rating");
	}
}

});