cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow and Document

thomasberment
Champ in-the-making
Champ in-the-making
Hi, I search how it's possible to modify my own document's properties in my workflow.

I think it's a script like :
<task-node name="review">
        <task name="wf:reviewTask" swimlane="reviewer">
            <event type="task-create">
                <script>
               document.properties['custom:statutdocument'] = 'En relecture';
               document.save;
          </script>
            </event>
        </task>
        <transition name="approve" to="approved" />
        <transition name="reject" to="rejected" />
    </task-node>

But it doesn't work ! I read the wiki and I find anything …
12 REPLIES 12

hsohaib
Champ on-the-rise
Champ on-the-rise
you reference the document as "bpm_package.children[0]" and not as "document", try this code it should work :


<task-node name="review">
        <task name="wf:reviewTask" swimlane="reviewer">
            <event type="task-create">
                <script>
               bpm_package.children[0].properties['custom:statutdocument'] = 'En relecture';
               bpm_package.children[0].save;
          </script>
            </event>
        </task>
        <transition name="approve" to="approved" />
        <transition name="reject" to="rejected" />
    </task-node>

thomasberment
Champ in-the-making
Champ in-the-making
I tried your code, but it doesn't work. I have an error like : Class or variable not found

[img]http://nsa14.casimages.com/img/2010/04/12/100412115002545839.jpg[/img]

sethatrothbury
Champ in-the-making
Champ in-the-making
Does the property custom:statutdocument actuatlly exist on your document?

thomasberment
Champ in-the-making
Champ in-the-making
Yes this property exists …

I tried this code, but I have an other error (03120030 Failed to signal transition 'null' from workflow task 'jbpm$40')

<start-state name="start">
        <task name="wf:submitReviewTask" swimlane="initiator" >
         <event type="task-end">
            <script>
               <variable name="bpm_package" access="read,write" />
               <expression>
                bpm_package.children[0].properties["custom:statutdocument"] = "En relecture";
                      bpm_package.children[0].save();
                      </expression>
            </script>
         </event>
      </task>
        <transition name="" to="review" />
    </start-state>

thomasberment
Champ in-the-making
Champ in-the-making
Hey, I tested this code and it works …

But what is the difference with my other code ?


<start-state name="start">
        <task name="wf:submitReviewTask" swimlane="initiator"/>
         <transition name="" to="review">
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                  <variable name="bpm_package" access="read" />
                  <expression>
                     bpm_package.children[0].properties["custom:statutdocument"] = "En relecture";
                       bpm_package.children[0].save();
                     </expression>
               </script>
            </action>
         </transition>  
    </start-state>

mrogers
Star Contributor
Star Contributor
There are many differences but we could start with the first script being BeanShell and the second being AlfrescoScript.

lucille_arkenst
Champ in-the-making
Champ in-the-making
But what is the difference with my other code ?
It appears as though the <script> code prefers to be inside an <action> tag where class is AlfrescoJavaScript due to the fact that we are setting properties.  Otherwise you would use:
<event type="quelque-chose">
<script>…

thomasberment
Champ in-the-making
Champ in-the-making
Thx for your reply …

I have an other question, is it possible to stop a workflow before it starts ?
I just want put a condition on the running workflow. And if the condition isn't validate, the workflow stops.

In a script in my "strat state" is a wrong idea because my workflow will start. But I think that it's possible to put a condition in the jsp page, on the list of workflow … ?

If you have an idea …

mrogers
Star Contributor
Star Contributor
If you throw an exception from your start task then a workflow instance will not have started.   The workflow only exists after completion of the start task.

Or you are correct you can put a guard condition before calling the workflow  either on your jsp page or you control code.   Or you can start the workflow but only progress once you have all the relevant information.    The choice is yours.