Script for child table not working

Hello
I have New Created doctype Repairing, it’s child table is Products, and both have status field in forms and both status fields are select field type. I need script for when i select Estimate in child table status field then automatically In parent doctype Status field updated to Estimate (Both have Estimate option in it).

note:- i created child table because i have to add multiple item to my Repairing form, that’s why i have add item link to child table (may be this note helpful to solve this issue)

Please help to solve this problem. i tried many script but not working

Anyone have this problem solution ??

Hi:

Try this:


frappe.ui.form.on('Yourchildtable, {
    status(frm,cdt,cdn) {
        let row = locals[cdt][cdn]
        if (row.status == "Estimate"){
            frm.set_value("status","Estimate")
        }
    }
})

Hope this helps

1 Like

Thank You SO MUCH BRO, It’s Working :love_you_gesture:

1 Like

Glad to been helpful.

Bonus track :wink:

Now … maybe you will need to check if any status of your child rows is “Estimated” … What will happen if you change back “Estimated” to other status (ie “Pending”) ? Status field on parent form won’t be updated …

So, … try this

frappe.ui.form.on('Yourchildtable', {
	status(frm,cdt,cdn) {
	    let anyEstimate = frappe.utils.filter_dict(frm.doc.child, {"status": "Estimate"}).length

        if (anyEstimate > 0){
            frm.set_value("status","Estimate")
        } else frm.set_value("status", "Pending")
        
	}
})

Play a little bit.
Hope this helps.

1 Like

I want to add more complexity :stuck_out_tongue: i have option (Pending, Estimate, Partially Complete, Partially Delivered, Complete & Delivered) in Parent doctype. and child table have option (Pending, Estimate, Complete, Delivered). In child table suppose 2 row added, then condition given below

child status (1row, 2row) - parent status (automatically update)
Pending, Pending - Pending
Pending, Estimate - Estimate
Pending, Complete - Partially Complete
Pending, Delivered - Partially Delivered
All Delivered - Delivered
& vice-versa

& Thanks For Reply :blue_heart:

1 Like

Hi:

Logic would be something like this …

frappe.ui.form.on('Yourchildtable', {
	status(frm,cdt,cdn) {
	    let numberOfLines = frm.doc.child.length // count lines on child
            let estimate = frappe.utils.filter_dict(frm.doc.child, {"status": "Estimate"}).length; // // count lines with "Pending" state
            let pending = frappe.utils.filter_dict(frm.doc.child, {"status": "Pending"}).length;
            let complete = frappe.utils.filter_dict(frm.doc.child, {"status": "Complete"}).length;
            let delivered = frappe.utils.filter_dict(frm.doc.child, {"status": "Delivered"}).length;
            

        if (estimate > 0){
            frm.set_value("status","Estimate")
        } else if (pending == numberOfLines) {
            frm.set_value("status", "Pending")
        } else if (complete > 0) {
           frm.set_value("status", "Pending") 
        } // add more logic to check all posibilities...	
    }
})

Probably it will be even more complex . What happens if Complete & Complete, Estimate & Complete …
Hope this helps.

It’s not working for me, but i Defiantly solve this problem

Thank for valuable reply.

1 Like

Edited. There was a syntax error … but it was just an example.
Happy if you solved :slight_smile:

1 Like