cancel
Showing results for 
Search instead for 
Did you mean: 

How to set a property before workflow transition

sgartner
Champ on-the-rise
Champ on-the-rise
I have a workflow in state A and I need to transition it to state B in JavaScript when a user does something in my application.  In order to transition to state B I need to set the due date that they have to complete B by.  I figured I would just set bpm:workflowDueDate to today + 7 days, but I can't figure out how to set a property in an existing workflow before transitioning.  Here's the code so far, with the taskID and transitionID coming in:


var taskId = args["taskId"];
var transitionId = args["transitionId"];
var task = workflow.getTaskById(taskId);
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 7);

// What do I do here, there is no setProperty or anything like it that I can find?
// task.setProperty("bpm:workflowDueDate", futureDate);

task.endTask(transitionId);

Help?
5 REPLIES 5

sgartner
Champ on-the-rise
Champ on-the-rise
Well, I thought I had found a solution.  Task has a getProperties() method and an undocumented setProperties() method.  I had hoped that if I called getProperties and modified the results I could then put them back in using setProperties before transitioning.  This does not work:


    var taskId = args["taskId"];
    var transitionId = args["transitionId"];
    var task = workflow.getTaskById(taskId);
    var futureDate = new Date();
    futureDate.setDate(futureDate.getDate() + 7);

    // This does *not* work, unfortunately
    var workflowProperties = task.getProperties();
    workflowProperties["bpm:workflowDueDate"] = futureDate;
    task.setProperties(workflowProperties);

    task.endTask(transitionId);

sgartner
Champ on-the-rise
Champ on-the-rise
Crap, according to this thread:
http://forums.alfresco.com/en/viewtopic.php?f=34&t=27349&p=89543&hilit=javascript+workflow+propertie...

Apparently Alfresco neglected to implement this vital component.  This means that only trivial workflows can be transitioned via JavaScript.

sgartner
Champ on-the-rise
Champ on-the-rise
Well, I figured out why the undocumented setProperties() function doesn’t work (and maybe why it’s undocumented).  The JscriptWorkflowTask class copies the properties from the task into the JScript object, and so when you do getProperties() it gives you back that copy.  When you do setProperties() it updates the copy but never reflects that back to the workflow.  Pretty pointless.

fordville
Champ on-the-rise
Champ on-the-rise
In the code below…where/how are you getting the transitionid?  How are you populating this in the previous step?  I can't seem to bring any value to this webscript that is actually the transitionid for an adhoc workflow.  I'm stuck here!


var transitionId = args["transitionId"];
var task = workflow.getTaskById(taskId);
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 7);


Help?

sgartner
Champ on-the-rise
Champ on-the-rise
In the code below…where/how are you getting the transitionid?  How are you populating this in the previous step?  I can't seem to bring any value to this webscript that is actually the transitionid for an adhoc workflow.  I'm stuck here!


var transitionId = args["transitionId"];
var task = workflow.getTaskById(taskId);
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 7);


Help?
Fordville,

I don't know if this will help, but here is a test script of mine that passes, among other things, transition IDs to a test script (with code similar to the above).  I am involved on a different project at the moment, so I can't test it, but I assume this script works.

listTasks.get.html.ftl:

My Tasks Todo:
<table cellspacing=0 cellpadding=2>
   <tr>
      <th>ID</th>
      <th>Type</th>
      <th>Name</th>
      <th>Created Date</th>
      <th>Due Date</th>
      <th>Priority</th>
      <th>% Complete</th>
      <th>Status</th>
      <th>Completed</th>
      <th>Transitions</th>
   </tr>
   <tr>
     <td colspan="11"><hr/></td>
   </tr>
   <#list workflow.assignedTasks as t>
      <tr>
         <td><a href="/alfresco/wcs/GreatApp/workflow/actionList?taskId=${t.id?html}">${t.id}</a></td>
         <td>${t.type}</td>
         <td>${t.name}</td>
         <td>${t.properties["cm:created"]?datetime}</td>
         <td><#if t.properties["bpm:dueDate"]?exists>${t.properties["bpm:dueDate"]?datetime}<#else><i>None</i></#if></td>
         <td>${t.properties["bpm:priority"]}</td>
         <td>${t.properties["bpm:percentComplete"]}</td>
         <td>${t.properties["bpm:status"]}</td>
         <td>${t.isCompleted?string("Yes", "No")}</td>
         <td>
            <#list t.transitions as transition>
                <#if !transition.label?contains(":internal")>
                    <span class="${t.id} ${transition.id}">
                      <a href="http://localhost:8080/alfresco/wcs/GreatApp/workflow/form?taskId=${t.id}&transitionId=${transition.l...">
                        ${transition.label?html}
                      </a>
                    </span>
                    <#if transition_has_next><span class="separator">|</span></#if>
                </#if>
            </#list>
         </td>
      </tr>
   </#list>
</table>

listTasks.get.desc.xml:

<webscript>
  <shortname>listTasks</shortname>
  <description>listTasks test</description>
  <url>/GreatApp/test/listTasks</url>
  <authentication>user</authentication>
  <transaction>required</transaction>
  <format default="html">any</format>
</webscript>

I hope this helps and good luck,

Scott