Set Value Into Child table 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

thanks for your kind reply…yes “Implement Plan” is the child doctype name

What is the main doctype name?

Main Doctype Name: Implementation Plan
Child Doctype Name: Implement Plan
Child Table Name: Plan
Child Table Field Name: tcd
Thanks In Advance

Ha, sorry I mixed up both names.

Change this to

frappe.ui.form.on(“Implementation Plan”, “validate”, function (frm, cdt, cdn) {

see if it triggers on save?

I changed and i tried but problem is i could not able to save…

Ok no need of validate method. Also try to check your date format is correct, hard code date first to see it it works?

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", "tcd", function(frm, cdt, cdn) {
                    frm.doc.tcd = get_today_date(30);
                    console.log(frm.doc.tcd);
                    cur_frm.refresh_field("plan");

});
1 Like

I think you better set “tcd” on setting of any other mandatory field in the child doc.