Tuesday, June 12, 2012

Default workflow message

Setting the default workflow message in share, based on the bpm package items

Two approaches possible. Override the java webscript FormUIGet or 'steal' the values from the start-workflow component (combobox).
see below form.control for a solution.

- Creating default messages ala: 'Review of myDoc.pdf'

I know the 'Review of ' is hardcoded, it could be pushed to a form.control.param :-)

Below is a freemaker template, which you can use in share-config-custom.xml ...




share-config-custom.xml 


<config evaluator="string-compare" condition="jbpm$wfl:customwfl">
        <forms>
            <form>
                <field-visibility>
                    <show id="bpm:workflowDescription" />
...
                </field-visibility>
                <appearance>
  
                    <field id="bpm:workflowDescription" label-id="workflow.field.message">
                        <control template="/com_redpill_linpro/components/form/controls/wf_preset_textarea.ftl">
               
                            <control-param name="style">width: 95%</control-param>
                        </control>
                    </field>
                    ...

wf_preset_textarea.ftl 


<#include "/org/alfresco/components/form/controls/textarea.ftl" />
 
 <#assign controlId = fieldHtmlId + "-cntrl">
    
 <#-- Below customization for default message -->

<script type="text/javascript">//<![CDATA[
            
   (function() {

            var onSuccess = function Wf_Preset_textArea_onSuccess(response)
             {
                var items = response.json.data.items,
                   item;
                if (0 < items.length) {
                    textArea = Dom.get("${fieldHtmlId}");
                    var message = "Review of ";
                    for (var i = 0, il = items.length; i < il; i++)
                    {
                      message += items[i].name;
                    }
                    textArea.innerHTML= message;
                }
    
             };
             
             var onFailure = function Wf_Preset_textArea_onFailure(response)
             {
                //empty
             };
      
             var startWorkflowComp = Alfresco.util.ComponentManager.get("${fieldHtmlId}".substring(0, "${fieldHtmlId}".indexOf("default") + 7));
             if (startWorkflowComp !== undefined) {
                Alfresco.util.Ajax.jsonRequest(
                {
                   url: Alfresco.constants.PROXY_URI + "api/forms/picker/items",
                   method: "POST",
                   dataObj:
                   {
                        items: startWorkflowComp.options.selectedItems.split(","),
                        itemValueType: "nodeRef"
                      
                   },
                   successCallback:
                   {
                      fn: onSuccess,
                      scope: this
                   },
                   failureCallback:
                   {
                      fn: onFailure,
                      scope: this
                   }
                });
            }
         })();
   
   //]]></script>