Goal
This post is for AEM users who wish to Start Workflow on assets from Asset Editor after adding or modifying metadata
Demo | Package Install
Starting a Workflow
If the Asset is already in Workflow
Solution
1) Login to CRXDE Lite (http://localhost:4502/crx/de) and create folder /apps/asset-editor-start-workflow
2) Create node /apps/asset-editor-start-workflow/clientlib of type cq:ClientLibraryFolder and add a String property categories with value cq.dam.admin
3) Create file (nt:file) /apps/asset-editor-start-workflow/clientlib/js.txt and add
add-workflow.js
4) Create file (nt:file) /apps/asset-editor-start-workflow/clientlib/add-workflow.js and add the following code. The dialog config for workflow was copied from \libs\cq\ui\widgets\source\widgets\wcm\SiteAdmin.Actions.js
(function(){ var isAlreadyInWorkflow = function(pagePath){ var url = CQ.HTTP.noCaching("/bin/workflow.json"); url = CQ.HTTP.addParameter(url, "isInWorkflow", pagePath); url = CQ.HTTP.addParameter(url, "_charset_", "UTF-8"); var response = CQ.HTTP.get(url); var isInWorkflow = false; if (CQ.HTTP.isOk(response)) { var data = CQ.Util.eval(response); isInWorkflow = data.status; } return isInWorkflow; }; var showWorkflowDialog = function(pagePath){ var id = CQ.Util.createId("cq-workflowdialog"); //this dialog config was copied from \libs\cq\ui\widgets\source\widgets\wcm\SiteAdmin.Actions.js var startWorkflowDialog = { "jcr:primaryType": "cq:Dialog", "title":CQ.I18n.getMessage("Start Workflow"), "id": id, "formUrl":"/etc/workflow/instances", "params": { "_charset_":"utf-8", "payloadType":"JCR_PATH" }, "items": { "jcr:primaryType": "cq:Panel", "items": { "jcr:primaryType": "cq:WidgetCollection", "model": { "xtype":"combo", "name":"model", "id": id + "-model", "hiddenName":"model", "fieldLabel":CQ.I18n.getMessage("Workflow"), "displayField":"label", "valueField":"wid", "title":CQ.I18n.getMessage("Available Workflows"), "selectOnFocus":true, "triggerAction":"all", "allowBlank":false, "editable":false, "store":new CQ.Ext.data.Store({ "proxy":new CQ.Ext.data.HttpProxy({ "url":"/libs/cq/workflow/content/console/workflows.json", "method":"GET" }), "baseParams": { tags: 'wcm' }, "reader":new CQ.Ext.data.JsonReader({ "totalProperty":"results", "root":"workflows" }, [ {"name":"wid"}, {"name":"label"}, {"name": CQ.shared.XSS.getXSSPropertyName("label")} ] ) }), "tpl": new CQ.Ext.XTemplate( '<tpl for=".">', '<div class="x-combo-list-item">', '{[CQ.I18n.getVarMessage(CQ.shared.XSS.getXSSTablePropertyValue(values, \"label\"))]}', '</div>', '</tpl>' ) }, "comment": { "jcr:primaryType": "cq:TextArea", "fieldLabel":CQ.I18n.getMessage("Comment"), "name":"startComment", "height":200 }, "title": { xtype: 'textfield', name:'workflowTitle', fieldLabel:CQ.I18n.getMessage('Workflow Title') } } }, "okText":CQ.I18n.getMessage("Start") }; var dialog = CQ.WCM.getDialog(startWorkflowDialog); dialog.addHidden({ "payload": pagePath } ); dialog.success = function(){ CQ.Ext.Msg.alert("Workflow","Workflow started on asset - " + pagePath); }; dialog.show(); }; var addWorkflowButton = function(bbar, pagePath){ var wButton = new CQ.Ext.Button({ "text": "Start Workflow", "cls": "cq-btn-save", "handler": function() { var isInWorkflow = isAlreadyInWorkflow(pagePath); if (isInWorkflow) { CQ.Ext.Msg.alert("Workflow", CQ.I18n.getMessage("Asset is already subject to a workflow!")); return; } showWorkflowDialog(pagePath); } }); bbar.insertButton(1, wButton); }; var INTERVAL = setInterval(function(){ var tabPanel = CQ.Ext.getCmp("cq-damadmin-tabpanel"); if(tabPanel){ clearInterval(INTERVAL); tabPanel.on("add", function(t, assetEditor){ addWorkflowButton(assetEditor.formPanel.getBottomToolbar(), assetEditor.path); }); } }, 250); })();
Hi,
ReplyDeletethere is also a way to add the complete button near it?
Tank you for any suggestions.
Hi, Editing DAM Asset redirected to Touch UI edit mode
ReplyDeleteIn classic mode
1) As an author, route a DAM Asset for workflow.
2) As approver, try to edit the content of the DAM asset routed in step 1.
Expected: Approver should be navigated to Classic UI edit mode.
Actual: Approver is routed to Touch UI edit mode
Please provide suggestions for this.