Try ERPNext Try Frappe Cloud Buy Support Partners Foundation

How can I give a confirmation dialog box when I change the workflow state?

I have a workflow defined, now when I click on “Approve” I want to give a frappe.confirm dialog box and if the user clicks the “Yes” then the doc should be approved, if “No” is clicked then the workflow state should remain unchanged.

I have tried do in the following way from the client side-
image

But I couldn’t figure out to stop the change of the workflow, frappe.validated = false doesn’t work
Can someone suggest a way here? Thank You.

I figured it out the below code is working

image

1 Like

I want to add a confirmation dialogue box for my workflow. Please tell me where do I need to add the code? I have added the following custom script for my doctype.

frappe.ui.form.on(‘Instrument’, {
refresh(frm) {
// your code here
frm.add_custom_button(‘Update Caliberation’, () => {
frappe.prompt({
label: ‘Latest Caliberation Date’,
fieldname: ‘date’,
fieldtype: ‘Date’},

        (values) => {
        // console.log(values.date);

    	var childTable = cur_frm.add_child("instrument_history");
        childTable.type="Calibration"
        childTable.start_date=values.date
        cur_frm.refresh_fields("project_item_list");
    	frm.save()
        });
	});
	
	
	    frm.add_custom_button('Update Prevention', () => {
        frappe.prompt({
        label: 'Latest Prevention Date',
        fieldname: 'date',
        fieldtype: 'Date'}, 
        
        (values) => {
        // console.log(values.date);

    	var childTable = cur_frm.add_child("instrument_history");
        childTable.type="Prevention"
        childTable.start_date=values.date
        cur_frm.refresh_fields("project_item_list");
    	frm.save()
        });
	});
	
}

})

here you need to add the trigger i.e. before_workflow_action: async (frm) => { ....
image
Check out my code above that’s how I used it.
And finally you need to add this line await promise.catch((err) => frappe.throw(err));
If you want to throw some error then add anything in the brackets of reject like reject("You can't Calibrate at this state")

1 Like

Thanks for sharing Sir.

I have a server-side validation (frappe.throw on Validate method) but it doesn’t shown up after adding this code.
Anything I missed ?

Thanks.
Subhajit