Button to save + workflow update

Hello,

I need to make a button on my “action” doctype which saves the form (i.e. the current doctype) and update the workflow status.

I created the button (called “done”) and I’m able to print message or update fields with it. But I can’t figure out how to save the doctype and update the workflow status. I tried two things but none works:(

  1. Write a server script in the .py file of the “action” doctype and call the method from js
    My .py code:

    @frappe.whitelist()
    def done():
    doc = frappe.get_doc(json.loads(frappe.form_dict.doc))
    set_local_name(doc)
    doc.save()
    My .js code:

    cur_frm.cscript.done = function(doc) {
    cur_frm.call({
    method: “done”,
    args: { }
    });
    }

  2. Call the savedocs method which is define in “frappe-bench/apps/frappe/frappe/desk/form/save.py” in my .js script:

    cur_frm.cscript.done = function(doc) {
    cur_frm.call({
    method: “frappe/frappe/desk/form/save.savedocs”,
    args: { }
    });
    }
    This option is obviously better if it works.

Anyone could put me on the right path here?

Thx!

@lleleu workflow status has to be updated client-side (unfortunately)

Oh ok ! And how can I save my doc and change the workflow status at the same time? I mean with one clic on a button field.

Just call the workflow action button. Workflow will trigger the save.

Ok, I’am not sure how to do this though. Do I have to call a py method or is it as simple as something like this:

cur_frm.cscript.done = cur_frm.workflow_action_done;

(this one doesn’t work of course).

You will have to find the button element from cur_frm.page and then trigger click. Hint: use jquery.

@rmehta I tried jquery to find the element. I was able to find all menu elements (under menu), but the Actions elements are not accesisble at all with jquery, Any suggestions?

I have tried the following -
//The below code doesnt get the elemenst under Action.
$( “div.btn-group.actions-btn-group.open” ).find(“a.grey-link”).each(function( index ) {

//The below code tries to find all the elements, and is able to find menu items, but not the Actions items (That are part of workflow)
console.log( index + ": " + $( this ).html() ); });
$( “div.offcanvas-container” ).find(“a.grey-link”).each(function( index ) {
console.log( index + ": " + $( this ).html() ); });

//The below code doesnt get the elemenst under Action.
$( “div.offcanvas-container” ).find(“btn-group-actions-btn-group”).each(function( index ) {
console.log( index + ": " + $( this ).html() ); });

Bump. I’m facing the same issue. Is there any solution to it?