Set Value Into Child table field

Hello guys,

              I am trying to set the date value into the child table field...taking the current date and i am adding + 30 days to the current date and i have to set into the childtable...i am geting the child date value from console i have to set it into the child table...

This is the following code:
frappe.ui.form.on(‘Implement Plan’, {
plan_add: function(frm,locals,cdt,cdn){
console.log(locals);
frappe.model.set_value(cdt,cdn,“tcd”,get_today_date(30));
cur_frm.refresh_fields(“tcd”);
}
});
function get_today_date(int) {
var d = new Date();
var result = d.setDate(d.getDate()+int);
console.log(new Date(parseInt(result)));
return new Date(parseInt(result));
};

Thanks in advance

2 Likes

Hi @rmehta any idea to set value into the childtable (need to get current date and have to add 30 days from the current date and set it to the child table field)

please don’t mention user(s) for general questions, its an open forum, people will reply whenever possible.

1 Like

Thanks For The Info

1 Like

I’ve been using

$.each(cur_frm.childtable || [], function(i, v) {
    frappe.db.get_value("Sales Invoice", v.reference_name, "fieldnameresult", function(r) {
        frappe.model.set_value(v.doctype, v.name, childfieldname, r.fieldnameresult)
    })
})

Thanks for the reply @outerlook can u explain this code and where i have to add this in my code i have posted my code in above…thanks in advance

In my console i am recieving the result of the date bt it is not setting into the childtable field

Is tcd is your child table name?

frm.refresh_field("tcd");

“tcd” is the childtable field name in that field only i have to set the date which shown in console

Does refresh field work?

Thanks for the reply… its not worked

Can share your updated code?

Thanks again,
frappe.ui.form.on(‘Implement Plan’, {
plan_add: function(frm,locals,cdt,cdn){
frappe.model.set_value(cdt,cdn,“tcd”,get_today_date(30));
frm.refresh_field(“tcd”);
}
});
function get_today_date(numb) {
var d = new Date();
var result = d.setDate(d.getDate() + (Number(numb)));
console.log(new Date(parseInt(result)));
return new Date(parseInt(result));
};

  1. Refresh child table name, not field in child table.
  2. What is plan_add? Is it child table name?
    Try to bind the field setting to [child_table_name]_on_form_rendered method of child table. So when you open the child table it will set the data field.

plan is the child table name… i tried to trigger the row so i gave plan_add when i add the row it will trigger…i tried what you said [plan]_on_rendered: instead of plan_add: and also i refresh the field with child table name…bt it displays as dashboard in UI…

Thanks In Advance

try this

function get_today_date(numb) {
    var d = new Date();
    var result = d.setDate(d.getDate() + (Number(numb)));
    return new Date(parseInt(result));
};

frappe.ui.form.on("Implementation Plan", "validate", function (frm, cdt, cdn) {
    var grid_row = cur_frm.open_grid_row();
    var child = grid_row.doc;
    child.tcd = get_today_date(30);
    cur_frm.refresh_field("plan");
});

frappe.ui.form.on("Child Doctype", "any_child_field", function(frm, cdt, cdn) {	
    frm.doc.tcd = get_today_date(30);
    cur_frm.refresh_field("plan");
});

Hi again, thanks for your help…i tried this but no response from UI

any error in console? screenshot?
have you changed the code according to your field names etc?

yes i have changed…

function get_today_date(numb) {
                        var d = new Date();
                        var result = d.setDate(d.getDate() + (Number(numb)));
                        console.log(result);
                        return new Date(parseInt(result));
 };

frappe.ui.form.on("Implement Plan", "validate", function (doc, grid_row) {
                        console.log(doc);
                        console.log(grid_row);
                        var grid_row = cur_frm.open_grid_row();
                        console.log(grid_row);
                        var child = grid_row.doc;
                        console.log(child);
                        child.tcd = get_today_date(30);
                        console.log(child.tcd);
                        cur_frm.refresh_field("plan");

});

frappe.ui.form.on("Implement Plan", "tcd", function(frm, cdt, cdn) {
                        frm.doc.tcd = get_today_date(30);
                        console.log(frm.doc.tcd);
                        cur_frm.refresh_field("plan");

});

This should be child doctype