[IMP] Unable to apply workflow action via custom script

Hi Team,

I have a custom client side script that calls the code

            method: 'frappe.workflow.doctype.workflow_action.workflow_action.apply_action',
            args: {
                doctype: frm.doc.doctype,
                docname: frm.doc.name,
                current_state: frm.doc.docstatus,
                action: 'SendToCmApproval'
        }).then(response => {
            console.log('Workflow action applied successfully:', response);
            frappe.msgprint('Document sent for CM approval successfully.');
            frm.reload_doc(); // Reload the document after successful workflow action
        }).catch(err => {
            console.error('Error applying workflow action:', err);
            frappe.msgprint('Failed to send document for CM approval.');

However, it is failing , I checked the api call logs and got error as

Invalid Link
This link is invalid or expired. Please make sure you have pasted correctly.

also, tried via

frm.set_value('workflow_state', 'CMPending');

which is also not working.

ASk - want to trigger workflow/update state based on condition and assign custom users for another script.

Can someone help on this??

Are you able to run:


In the console directly?



VM21261:1 Uncaught TypeError: Cannot read properties of undefined (reading ‘workflow_action’)
at :1:25