cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to execute script, returns null.

e-no91
Champ in-the-making
Champ in-the-making
I've added a custom workflow in …/classes/alfresco/extension

pengesahan_processdefinition.xml

<?xml version="1.0" encoding="UTF-8"?>

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wf:pengesahan">

    <swimlane name="initiator" />

    <start-state name="start">
        <task name="wf:submitGroupReviewTask" swimlane="initiator" />
        <transition name="" to="review" />
    </start-state>

    <swimlane name="reviewer">
        <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
            <pooledactors>#{bpm_groupAssignee}</pooledactors>
        </assignment>   
    </swimlane>

    <task-node name="review">
<timer name="emailReminderTimer" duedate="8 minutes">
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <script>
logger.log("send email");
var mail = actions.create("mail");
var node = people.getGroup(bpm_groupAssignee);
if(node)
{
var members = people.getMembers(node);        
}
mail.parameters.subject=bpm_mailSubject;
mail.parameters.text=bpm_mailText;
mail.parameters.from = "alfrescousername@gmail.com";

for(var i=0;i &lt; members.length;i++)
{
mail.parameters.to = members.properties.email;
mail.execute(bpm_package);
}
                </script>
            </action>
        </timer>
        <task name="wf:reviewTask" swimlane="reviewer">
            <event type="task-create">
                <script>
                   if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
                   if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
                </script>
            </event>
            <event type="task-end">
               <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                  <script>
                     <variable name="bpm_assignee" access="write"/>
                     <expression>
                        if (taskInstance.actorId != null)
                           people.getPerson(taskInstance.actorId);
                        else
                           person;
                     </expression>
                  </script>
               </action>
            </event>
        </task>
        <transition name="Approve" to="approved"/>
        <transition name="Reject" to="rejected"/>
    </task-node>

    <task-node name="rejected">
        <transition name="" to="end" >
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<runas>admin</runas>
<script>
logger.log("reject");
var dest = companyhome.childByNamePath(bpm_rejectDestination);
for (var i = 0 ; i &lt; bpm_package.children.length; i++)
{
bpm_package.children.move(dest);
}
</script>
</action>
</transition>
    </task-node>

    <task-node name="approved">
        <transition name="" to="end">
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<runas>admin</runas>
<script>
if(bpm_package.children[0].mimetype!="application/pdf")
{
var contentPdf = bpm_package.children[0].transformDocument("application/pdf",dest);
}
else
{
logger.log("pdf");
var contentCopy = bpm_package.children[0].copy(dest);
}
</script>
</action>
</transition>
    </task-node>

    <end-state name="end" />

</process-definition>


pengesahan-workflow-context.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN'
   'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>

   <bean id="parallel.workflowBootstrap" parent="workflowDeployer">
      <property name="workflowDefinitions">
         <list>
            <props>
               <prop key="engineId">jbpm</prop>
               <prop key="location">
                  alfresco/extension/pengesahan_processdefinition.xml
               </prop>
               <prop key="mimetype">text/xml</prop>
               <prop key="redeploy">true</prop>
            </props>
         </list>
      </property>
   </bean>

</beans>


and my javascript to call the workflow

var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "jbpm$wf:pengesahan";
workflow.parameters["bpm:workflowDescription"] = "Proses pengesahan dokumen : "+document.properties.name;
workflow.parameters["bpm:groupAssignee"] = "GROUP_KETUA URUSETIA SEKRETARIAT";
workflow.parameters["bpm:approveDestination"] = "Sites/ar-rahnutest/documentLibrary/PAPARAN";
workflow.parameters["bpm:rejectDestination"] = "Sites/ar-rahnutest/documentLibrary/TIDAK DILULUSKAN";
var futureDate = new Date();
   futureDate.setDate(futureDate.getDate() + 3);
   workflow.parameters["bpm:workflowDueDate"] = futureDate;
workflow.parameters["bpm:workflowPriority"]="2";
workflow.parameters["bpm:mailSubject"]="Peringatan : Sila lakukan pengesahan";
workflow.execute(document);


Actually this is my second custom workflow. The first one works fine. The only difference is the wf:name and the xml filenames.
This new custom workflow would return unable to execute script because of null (after checking with logs, this I believe happens at line workflow.execute()).

Maybe I've missed something?

Thanks in advance.
6 REPLIES 6

kaynezhang
World-Class Innovator
World-Class Innovator
Have you ever checked whether your process definition is successfully deployed using workflow console?

e-no91
Champ in-the-making
Champ in-the-making
Hi, Thank you for the reply.

I've just checked and found out that instead of running the workflow, it runs the previous workflow that I used, wf:reviewpooled.
But I set the name as wfSmiley Tongueengesahan, to run that workflow, what mistake have I done here?

kaynezhang
World-Class Innovator
World-Class Innovator
1.Excecute "show definitions" command in workflow console ,make sure your definition is successfully deployed and make sure you specify the correct definition name in your javascrpt code.
2.I guess maybe you made somewhere,you can write your javascript code like below and it will give you more log info.

var wfdef = workflow.getDefinitionByName("jbpm$wf:pengesahan");
logger.getSystem().out(wfdef.getName());

var wfparams = new Object();
wfparams["bpm:workflowDescription"] = "Proses pengesahan dokumen : "+document.properties.name;
wfparams["bpm:groupAssignee"] = "GROUP_KETUA URUSETIA SEKRETARIAT";
wfparams["bpm:approveDestination"] = "Sites/ar-rahnutest/documentLibrary/PAPARAN";
wfparams["bpm:rejectDestination"] = "Sites/ar-rahnutest/documentLibrary/TIDAK DILULUSKAN";
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 3);
wfparams["bpm:workflowDueDate"] = futureDate;
wfparams["bpm:workflowPriority"]="2";
wfparams["bpm:mailSubject"]="Peringatan : Sila lakukan pengesahan";
var wfpackage = workflow.createPackage();
wfpackage.addNode(document);
wfdef.startWorkflow(wfpackage,wfparams);

e-no91
Champ in-the-making
Champ in-the-making
Hi,
Thank you! I'll try this out later.
I have to test out other things so I have to stick to using and editing from the workflow folder..

Hi,
When you re-deploy your worklow in alfresco, it creates new version of the workflow.
So, please use the workflow console and find out how many versions of workflow you have.

Thanks.
Murali

e-no91
Champ in-the-making
Champ in-the-making
Hi,
Does this means that it is better to leave the redeploy parameter as false?
So everytime I make changes to the workflow, does it still take effect?

Thank you.