Update child table based on workflow_state

I have created workflow for my job card doctype, when user select particular action from the action button it also updates the job card status . In the Job Card I have created child table which i want to update based on the action selection.

In below screenshot my current jobcard Status is “Fabrication Complete” and now if the user select “Send to Copper platting” i want to create an entry into my “cylinder events” child table with below:
Old status name = Fabrication Complete, New Status Name = “Send to Copper platting”, Date Time = “time when the action was selected”

same if the person selects Rejected it should create an entry into cylinder event table as below:
Old status name = “Fabrication Complete”, New Status Name = “Rejected”, Date Time = “time when the action was selected”

That for, you have to use the server logic and set it according to the scenario.

Hello @Mite87

According to your scenario, You create a javascript code on fieldname event.

frappe.ui.form.on('Doctype Name', {
     workflow_state: function(frm){
                Here you write the logic
     }
});

Above will execute when workflow_state is changed.

I could not make the script to work to update table so i changed the approach and created custom fields where i am updating the date and time when user select the workflow step. This works fine when i am in the job card doctype but when i am selecting the same action when in the list view its not updating the field with date and time. any suggestion on how to make the same script work for the job card and the list view of the job card?

here is my code for the updating fields based on workflow action:

frappe.ui.form.on('Job Card', {
//	refresh(frm) 
		  after_workflow_action: (frm) => {
        if (frm.doc.workflow_state === 'Fabrication In Process') {
            console.log(frm.after_workflow_state);
            frm.set_value({
                custom_fabrication_start: frappe.datetime.now_datetime()
            
            });
            frm.save();
        }
        if (frm.doc.workflow_state === 'Fabrication Complete') {
            frm.set_value({
                custom_fabrication_end: frappe.datetime.now_datetime()
            }); 
            
            frm.save();
        }
    }
});