Activiti workflow: setting value of an aspect from StartTask - alfresco

I need to set a value from a text field on my start form and then pull this information on several other tasks. To do this, I'm using an aspect and trying to send the data up to the execution variable, and then pull it down.
The problem is that I cannot send the value from the start form to the execution variable. As it is now, Share will just say that the workflow cannot be started.
I am using Alfresco 4.2.f Community edition.
The start event is defined in the BPMN as follows:
<startEvent id="start" name="Start Delivery Ticket Workflow" activiti:initiator="initiatorUserName" activiti:formKey="deliveryTicketWorkflow:start">
<documentation>Project Manager initiates workflow. A customer purchase order is provided, along with the specific line items for the delivery ticket.</documentation>
<extensionElements>
<activiti:executionListener class="org.alfresco.repo.workflow.activiti.listener.ExecutionListener" event="start">
<activiti:field name="script">
<activiti:string><![CDATA[
execution.setVariable('deliveryTicketWorkflow_requestdetailstext', task.getVariable('deliveryTicketWorkflow_requestdetailstext'));;
]]></activiti:string>
</activiti:field>
</activiti:executionListener>
</extensionElements>
</startEvent>
The relevant parts of my model are:
<type name="deliveryTicketWorkflow:start">
<parent>bpm:startTask</parent>
<properties />
<associations />
<overrides />
<mandatory-aspects>
<aspect>deliveryTicketWorkflow:requestdetails</aspect>
</mandatory-aspects>
</type>
[...]
<aspect name="deliveryTicketWorkflow:requestdetails">
<properties>
<property name="deliveryTicketWorkflow:requestdetailstext">
<title>Specific Details</title>
<type>d:text</type>
<mandatory>true</mandatory>
<multiple>false</multiple>
</property>
</properties>
</aspect>
In the config:
<config condition="deliveryTicketWorkflow:start" evaluator="task-type">
<forms>
<form>
<field-visibility>
<show id="packageItems"/>
<show id="deliveryTicketWorkflow:requestdetailstext"/>
<show id="transitions"/>
</field-visibility>
<appearance>
<set appearance="title" label-id="Prepare Delivery Ticket" id="info"/>
<field set="info" id="packageItems"/>
<field set="info" label-id="Request Details" id="deliveryTicketWorkflow:requestdetailstext">
<control template="/org/alfresco/components/form/controls/info.ftl"/>
</field>
<set id="response"/>
<field set="response" id="transitions"/>
</appearance>
</form>
</forms>
</config>
[...]
<config condition="activiti$deliveryTicketWorkflow" evaluator="string-compare">
<forms>
<form>
<field-visibility>
<show id="bpm:workflowPriority"/>
<show id="packageItems"/>
<show id="deliveryTicketWorkflow:requestdetails"/>
<show id="transitions"/>
<show id="deliveryTicketWorkflow:approveRejectOutcome"/>
</field-visibility>
<appearance>
<set appearance="title" label-id="Request Delivery Ticket" id="info"/>
<field set="info" label-id="workflow.field.priority" id="bpm:workflowPriority">
<control template="/org/alfresco/components/form/controls/workflow/priority.ftl"/>
</field>
<field set="info" id="packageItems"/>
<field set="info" label-id="Request Details" id="deliveryTicketWorkflow:requestdetails">
<control template="/org/alfresco/components/form/controls/textarea.ftl"/>
</field>
<set id="response"/>
<field set="response" id="approveRejectOutcome">
<control template="/org/alfresco/components/form/controls/workflow/activiti-transitions.ftl"/>
</field>
<field set="response" id="transitions"/>
</appearance>
</form>
</forms>
</config>
I have seen at least one question here that was similar, but the answers were stating to use task listeners for the start form. I'm not sure at all how that is intended to function, because it seems like a start task isn't a "true" task and can only use ExecutionListeners. The difference should be small, but it seems that any reference to "task" in the start task will either cause a failure or just have no affect at all. Becasue I can't use task.getVariableLocal() to get the value, I don't see what to give to execution.setVariable() as the value.

In my experience, all values of aspects and properties in a start task are automatically copied to the executionContext and are already available for future tasks.
Try removing the executionlistener in your BPMN, you shouldnt need that. Then try making a starttasklistener on your subsequent task that copyies the value from your execeutioncontext into this task. It should work fine.
Getting the var back from your executioncontext in your subsequent task should work like this:
<activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="language" stringValue="groovy" /
<activiti:field name="script">
<activiti:string><![CDATA[
System.out.println(execution.getVariable("deliveryTicketWorkflow_requestdetailstext"));
if (execution.getVariable("deliveryTicketWorkflow_requestdetailstext") != null){
task.setVariableLocal('deliveryTicketWorkflow_requestdetailstext', execution.getVariable("deliveryTicketWorkflow_requestdetailstext"));
}]]>
</activiti:string>
</activiti:field>
</activiti:taskListener>

This is a long shot but in your share form, your custom field is using the info control:
I believe you need there to be a regular field there, the info field is to display text, AFAIK, it doesn't include an input field and won't send anything to the workflow start.

Related

Alfresco - documents list on workflow details page

I would like to know how the document list is rendered on workflow details page in Alfresco Share. I mean which components (Java class, Java script, FTL, XML) are responsible to add document list on in workflow-details page.
I searched through the code and found workflow-form.get.html.ftl, however it takes care of all other data to be rendered on this page except document list. Its getting populated dynamically it seems but I don't understand how.
Thanks,
Hemant
If you look at the source on that page you'll find a clue:
<label for="page_x002e_data-form_x002e_task-edit_x0023_default_assoc_packageItems-cntrl">Items:</label>
If you go grep for "packageItems" you'll soon find that a form control called packageitems.ftl:
target/share-war/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/form/controls/workflow/packageitems.ftl
If you go look at that form control it should give you a good starting point in understanding how it works.
It was always confusing for me as well.For defining the workflow details field, there is a separate form for it.
For each workflow there is start task which we are defining in workflow model.for this start task we need to define workflow details form as well.
Below is one of the example where for bpm:startTask workflow-details form is defined.
<config evaluator="task-type" condition="bpm:startTask">
<forms>
**<form id="workflow-details">
<field-visibility>
<show id="bpm:sendEMailNotifications" />
<show id="packageItems" />
</field-visibility>
<appearance>
<set id="" appearance="title" label-id="workflow.set.workflow.more_info" />
<set id="items" appearance="title" label-id="workflow.set.items" />
<field id="packageItems" set="items" />
</appearance>
</form>**
<form>
<field-visibility>
<show id="message" />
<show id="taskOwner" />
<show id="bpm:workflowPriority" />
<show id="bpm:workflowDueDate" />
<show id="bpm:taskId" />
<show id="bpm:status" />
<show id="packageItems" />
<show id="bpm:sendEMailNotifications" />
</field-visibility>
<appearance>
<set id="" appearance="title" label-id="workflow.set.task.info" />
<set id="info" appearance="" template="/org/alfresco/components/form/3-column-set.ftl" />
<set id="progress" appearance="title" label-id="workflow.set.task.progress" />
<set id="items" appearance="title" label-id="workflow.set.items" />
<set id="other" appearance="title" label-id="workflow.set.other" />
<field id="message">
<control template="/org/alfresco/components/form/controls/info.ftl" />
</field>
<field id="taskOwner" set="info" />
<field id="bpm:taskId" set="info">
<control template="/org/alfresco/components/form/controls/info.ftl" />
</field>
<field id="bpm:workflowPriority" label-id="workflow.field.priority" set="info" read-only="true">
<control template="/org/alfresco/components/form/controls/workflow/priority.ftl" />
</field>
<field id="bpm:workflowDueDate" set="info" label-id="workflow.field.due">
<control template="/org/alfresco/components/form/controls/info.ftl" />
</field>
<field id="bpm:status" set="progress" />
<field id="bpm:sendEMailNotifications" set="other" />
<field id="packageItems" set="items" />
</appearance>
</form>
</forms>
If you would like to change anything in document list rendering you can extend packageitems.ftl which is suggested by Jeff.

display workflow task custom properties on edit task page only (not on workflow details or task details page) alfresco share

I need to hide workflow task custom properties from the workflow-details and task-details page and show only on task-edit page.Currently it is visible on all the three pages.
abcmodel.xml
<type name="abc:review">
<parent>bpm:activitiOutcomeTask</parent>
<mandatory-aspects>
<aspect>abc:Info</aspect>
</mandatory-aspects>
</type>
<aspects>
<aspect name="abc:Info">
<properties>
<property name="abc:Det">
<type>d:mltext</type>
</property>
</properties>
</aspect>
</aspects>
shareconfigcustom.xml
<config evaluator="task-type" condition="abc:review">
<forms>
<form>
<field-visibility>
<show id="abc:Det"/>
<show id="bpm:comment" />
</field-visibility>
<appearance>
<field id="abc:Det" label="customproperty" read-only="true">
<control template="/org/alfresco/components/form/controls/textarea.ftl">
<control-param name="style">color: black</control-param>
<control-param name="rows">6</control-param>
<control-param name="columns">6</control-param>
</control>
</field>
<field id="bpm:comment" label="Comments">
<control template="/org/alfresco/components/form/controls/textarea.ftl" />
</field>
</appearance>
</form>
</forms>
</config>
You can use form-id to control them.
To hide the field(abc:det) in the workflow details page, you can use like,
<config evaluator="task-type" condition="abc:review">
<forms>
<form>
<field-visibility>
<show id="abc:Det"/>
<show id="bpm:comment" />
</field-visibility>
<appearance>
<field id="abc:Det" label="customproperty" read-only="true">
<control template="/org/alfresco/components/form/controls/textarea.ftl">
<control-param name="style">color: black</control-param>
<control-param name="rows">6</control-param>
<control-param name="columns">6</control-param>
</control>
</field>
<field id="bpm:comment" label="Comments">
<control template="/org/alfresco/components/form/controls/textarea.ftl" />
</field>
</appearance>
</form>
<!-- Form configuration for workflow-details page -->
<form id="workflow-details">
<field-visibility>
<hide id="abc:Det"/>
<show id="bpm:comment" />
</field-visibility>
<appearance>
.....
</appearance>
</form>
<!-- Form configuration for task-details page -->
<form id="task-details">
<field-visibility>
<hide id="abc:Det"/>
<show id="bpm:comment" />
</field-visibility>
<appearance>
.....
</appearance>
</form>
</forms>
</config>
I hope you can use, '' to configure the task-details, but I haven't tried it yet.
Update
For the task-details, there is no specific form-id is used in data-form section. Refer C:\<Alfresco_Home>\tomcat\webapps\share\WEB-INF\classes\alfresco\site-data\pages\task-details.xml
<!-- Data Form -->
<component>
<region-id>data-form</region-id>
<url>/components/form</url>
<properties>
<itemKind>task</itemKind>
<itemId>{taskId}</itemId>
<mode>view</mode>
<formUI>true</formUI>
</properties>
</component>
To customise this task-details form, I added <formId>task-details</formId> as mentioned below.
<!-- Data Form -->
<component>
<region-id>data-form</region-id>
<url>/components/form</url>
<properties>
<itemKind>task</itemKind>
<itemId>{taskId}</itemId>
<mode>view</mode>
<formUI>true</formUI>
<formId>task-details</formId>
</properties>
</component>
You need to use share extension / customisation best practices to change the OOTB files in share.
Alfresco Share extensions
Finally in the share-config-custom.xml file add the configuration like,
<form id="task-details">
<field-visibility>
<hide id="abc:Det"/>
<show id="bpm:comment" />
</field-visibility>
<appearance>
.....
</appearance>
</form>
All set to go and it is working fine to me.

text size limit not resizing properly at the create content form

shareconfigcustom.xml
text box accepts unlimited characters with these parameters not resizing properly at the create form alfresco but working in edit-form(accepts defined number of characters)
Also is there any maximum limit for the number of characters ?
<config evaluator="node-type" condition="acme:document">
<forms>
<form>
<field-visibility>
<show id="acme:anycustomproperty"/>
</field-visibility>
<appearance>
<field id="acme:anycustomproperty" label-id="xqw">
<control template='/org/alfresco/components/form/controls/textfield.ftl' />
<control-param name='maxlength'>5000</control-param>
<control template='/org/alfresco/components/form/controls/textarea.ftl' />
<control-param name='rows'>10</control-param>
<control-param name='columns'>10</control-param>
</field>
</appearance>
</form>
</forms>
</config>
textatrea.ftl only provides, rows & columns property. Please ensure that, you've used textarea.ftl, but your post says, that you've used, textfield.ftl.
textarea.ftl
<#if field.control.params.rows??><#assign rows=field.control.params.rows><#else><#assign rows=3></#if>
<#if field.control.params.columns??><#assign columns=field.control.params.columns><#else><#assign columns=60></#if>
This configuration worked for me for edit and creation page as well
<control template="/org/alfresco/components/form/controls/textarea.ftl">
<control-param name="rows">4</control-param>
<control-param name="columns">4</control-param>
<control-param name="maxLength">5000</control-param>
</control>

Colon is not replaced by underscore in name of the property when passed to end-event script

I am trying to define workflow in Alfresco 4.2. I have a type defined as follows:
<type name="abc:start">
<parent>bpm:startTask</parent>
<associations>
<association name="abc:client">
<source>
<mandatory>true</mandatory>
<many>true</many>
</source>
<target>
<class>cm:person</class>
<mandatory>false</mandatory>
<many>false</many>
</target>
</association>
</associations>
</type>
This type is used start event of an workflow:
<config evaluator="string-compare" condition="activiti$sa05">
<forms>
<form>
<field-visibility>
<show id="packageItems" />
<show id="abc:client"/>
</field-visibility>
<appearance>
<set id="items" appearance="title" />
<set id="info" appearance="title" />
<field id="packageItems" set="items" />
<field id="abc:client" set="info" />
</appearance>
</form>
</forms>
In the event I have a very simple script (started at end of event), which uses this association:
logger.log("Starting workflow for: " + abc_client);
execution.setVariable("abc:client", abc_client);
When I start workflow for the first time, everything is ok. When I start it for the second time, I get the following error:
Failed to execute supplied script: 01240010 ReferenceError: "abc_client" is not defined. (AlfrescoJS#2)
I set a breakpoint in RhinoScriptProcessor and I was able to see that "abc:client" gets passed to script, rather then "abc_client". Why is it so? Why this isn't deterministic?
It turns out that the following line was problematic:
execution.setVariable("abc:client", abc_client);
Alfresco keeps an internal cache of two-way-mapping: qualified name <-> variable name. On first execution of workflow {abc namespace}client is mapped to abc_client. But then the above line gets executed and now {abc namespace}client is mapped to abc:client. As the result, on the next execution of the workflow abc:client is passed, rather then abc_client.

Alfresco CMS issues

We have Alfresco (Community Edition 4.2) environment set on Server. WE created some websites and Custom content model and deployed on server.
We are facing following issues which need to resolved.
RTF Field : In custom content model we have defined a rtf field. This rtf field is not saving its value.
Folder Creation: There is no option available to create Folders in Document library.
Web Script Query: We need to write webscript queries to fetch the data for each website separately.
following is code from share-forms-config for RTF fields
<config evaluator="node-type" condition="custom:questionscategory">
<forms>
<!-- Default form configuration for the cm:content type -->
<form>
<field-visibility>
<show id="cm:name" />
<show id="custom:categoyTitle" />
<show id="custom:categoryDesc" />
</field-visibility>
<appearance>
<field id="custom:categoryDesc">
<control template="/org/alfresco/components/form/controls/richtext.ftl">
<control-param name="editorAppearance">full</control-param>
</control>
</field>
</appearance>
</form>
<form id="doclib-simple-metadata">
<field-visibility>
<show id="cm:name" />
<show id="custom:categoyTitle" />
<show id="custom:categoryDesc" />
</field-visibility>
<appearance>
<field id="custom:categoryDesc">
<control template="/org/alfresco/components/form/controls/richtext.ftl">
<control-param name="editorAppearance">full</control-param>
</control>
</field>
</appearance>
</form>
</forms>
</config>
<config evaluator="model-type" condition="custom:questionscategory">
<forms>
<!-- Default form configuration for the cm:content type -->
<form>
<field-visibility>
<show id="cm:name" />
<show id="custom:categoyTitle" />
<show id="custom:categoryDesc" />
</field-visibility>
<appearance>
<field id="custom:categoryDesc">
<control template="/org/alfresco/components/form/controls/richtext.ftl">
<control-param name="editorAppearance">full</control-param>
</control>
</field>
</appearance>
</form>
</forms>
</config>
here is the query I have written to fetch data..I need to add website name to it
// locate folder by path
// NOTE: only supports path beneath company home, not from root
var query='TYPE:custom\:questionscategory';
var fbaQuetions = search.luceneSearch(query);
if (fbaQuetions== undefined || fbaQuetions.isContainer)
{
status.code = 404;
status.message = "fbaQuetions " + url.extension + " not found.";
status.redirect = true;
}
model.folder = fbaQuetions;
For number 2. The answer probably lies in lack of permissions, make sure you have the right privileges in the site, that is at least contributor.
To answer your other questions we need more information:
What do you mean by RTF-field? What datatype are we talking about? Could you post snippets from your custom model togheter with the appropriate share-forms-config section?
There are a lot of webscripts present to fetch data per site. In fact Alfresco Share only uses webscripts to talk to the repository. What data do you need?
Update: Extend your search query with a "+PATH" which searches just in your site expression.
ie: "PATH:"/app:company_home/st:sites/cm:yoursiteshortname//*"
This looks like a bug that has been patched, I've got a similar problem.
https://issues.alfresco.com/jira/browse/MNT-10238?jql=text%20~%20%22r57658%22
I'm going to upgrade to get the patch.

Resources