I’m trying to invoke the worflow action through js. I dont know howto get hold of the action buttons. Any ideas?
I need something like Approve.click() or Reject.click()
Thanks.
I’m trying to invoke the worflow action through js. I dont know howto get hold of the action buttons. Any ideas?
I need something like Approve.click() or Reject.click()
Thanks.
@kirthi, the unique thing that the click
do is update the workflow_state
field, and invoque the frm.save_or_update
function!
Great!!! it worked @max_morais_dmm
My code - just in case anyone is looking for a reference -
frappe.ui.form.on(“Purchase Order”, “validate”, function(frm) {
if (frm.doc.approval_state == ‘Pending Approval’ && frm.doc.authorized_tmp != ‘Yes’) {
validated = false;
//do your stuff
}
else if (frm.doc.approval_state == ‘Approved’ && frm.doc.authorized_tmp != ‘Yes’) {
validated = false;
//do your stuff
}
else { frm.doc.authorized_tmp = ‘No’;}
});
I needed to add a tmp variable to prevent cyclic loop of saving/submission.
Hello @max_morais_dmm ,
May I request for your advice!
In JS, I want to catch the workflow action, validate some field value, (if not validated ) set focus to the said field and stop workflow action (i.e. stop the change of workflow_state). Please guide me.
Regards
Mijan
if I’m not wrong the easier way is
frappe.ui.form.on('My DocType', {
validate(frm){
if (frm.doc.workflow_state === 'My Workflow State'){
validated = frm.doc.my_field > 10; // validation condition needs to be assigned to validated variable
if (!validated) frappe.throw("Oups wrong condition!");
}
}
});