Alfresco: linking directly to workflow

519 Views Asked by At

I would like to start a workflow from the site links dashlet on my Alfresco site. Using Firebug to examine the POST gives me a URL that works, but it only displays the form without any UI:

http://localhost:8081/share/service/components/form?htmlid=template_x002e_start-workflow_x002e_start-workflow_x0023_default-startWorkflowForm-alf-id1&itemKind=workflow&itemId=activiti%24orpWorkflow&mode=create&submitType=json&showCaption=true&formUI=true&showCancelButton=true&destination=
  1. Is this possible? And if so, how can I format the link to include the UI?
  2. If not, are there custom dashlets out there designed for starting workflows?
3

There are 3 best solutions below

0
On

You can make a little customization for Share.

For example, if you need to open the start form of any business process, you can find its index in the popup and add an additional parameter to the URL (let's say, openFormParam).

In start-workflow.js:

onReady: function StartWorkflow_onReady() {
    // skipped ...
    // get the additional parameter from the URL here
    // var openFormParam = ...

    if(openFormParam !== null) {
        var p_aArgs = [];
        var index = {index: 0}; // for the first workflow in the popup

        p_aArgs.push(0, index);
        this.onWorkflowSelectChange(null, p_aArgs);
    }

    return Alfresco.component.StartWorkflow.superclass.onReady.call(this);
},

 // OOTB
onWorkflowSelectChange: function StartWorkflow_onWorkflowSelectChange(p_sType, p_aArgs) {
    var i = p_aArgs[1].index;
    if (i >= 0) {
        // Update label of workflow menu button
        var workflowDefinition = this.options.workflowDefinitions[i];
        this.widgets.workflowDefinitionMenuButton.set("label", workflowDefinition.title + " " + Alfresco.constants.MENU_ARROW_SYMBOL);
        this.widgets.workflowDefinitionMenuButton.set("title", workflowDefinition.description);

        // Load the form for the specific workflow
        Alfresco.util.Ajax.request({
            url: Alfresco.constants.URL_SERVICECONTEXT + "components/form",
            dataObj: {
                htmlid: this.id + "-startWorkflowForm-" + Alfresco.util.generateDomId(),
                itemKind: "workflow",
                itemId: workflowDefinition.name,
                mode: "create",
                submitType: "json",
                showCaption: true,
                formUI: true,
                showCancelButton: true,
                destination: this.options.destination
            },
            successCallback: {
                fn: this.onWorkflowFormLoaded,
                scope: this
            },

            failureMessage: this.msg("message.failure"),
                scope: this,
                execScripts: true
        });
    }
},
4
On

When you select workflow from dropdown it will generate url based on selected workflow and redirect you to that.

Ex. For ParallelGroupReview workflow URL is.

http://localhost:8080/share/service/components/form?htmlid=template_x002e_start-workflow_x002e_start-workflow_x0023_default-startWorkflowForm-alf-id1&itemKind=workflow&itemId=activiti%24activitiParallelGroupReview&mode=create&submitType=json&showCaption=true&formUI=true&showCancelButton=true&destination=

Now if you use this url directly in browser you will be able to see same form but header and footer part will be missing, because those global components will not be avilable outside of share context.

If you see start-workflow.ftl you will be able to see header and footer components are inserted which are responsible for rest of the UI.

<#include "include/alfresco-template.ftl" />
<@templateHeader />

<@templateBody>
   <@markup id="alf-hd">
   <div id="alf-hd">
      <@region scope="global" id="share-header" chromeless="true"/>
   </div>
   </@>
   <@markup id="bd">
   <div id="bd">
      <div class="share-form">
         <@region id="start-workflow" scope="template"/>
      </div>
   </div>
   </@>
</@>

<@templateFooter>
   <@markup id="al-ft">
   <div id="alf-ft">
      <@region id="footer" scope="global"/>
   </div>
   </@>
</@>

You can reuse same component just need to make sure header and footer are initialized properly.

2
On

I created an extension module which has the following target:

<targetPackageRoot>org.alfresco.components.workflow</targetPackageRoot>

I included the following piece in my extended start-workflow.get.html.ftl:

<@markup id="start-workflow-js" target="js" action="after">
   <@script src="${url.context}/res/components/workflow/initiate-workflow.js" group="workflow"/>
</@>

to extend the default start-workflow.js of my own.

You'll need to change the following methods:

  • onReady: so it reads your param from the url to know which workflowdefinition to start and fire onWorkflowSelectChange
  • onWorkflowSelectChange: So it reads the workflowdefintion to load the form