cancel
Showing results for 
Search instead for 
Did you mean: 

Access content in workflow package

boneill
Star Contributor
Star Contributor
Hi,

I have developed a custom workflow for WCM based on the submit to staging workflow.  It has a custom decision step called validcontent.  This step should check if the attached workflow content meets a number of business rules and if so the decision should transition according to the result. 

Can anyone tell me how I can get access to the attached content nodes.  I have tried via the bpm_package.  It seems to be returning a store ID but that store cannot be instantiated in the node using var store = avm.lookupStore(bpm_package.getStoreId()); call. 

Can anyone point me in the right direction on how to get access to the content in the workflow node using the javascript api.   Is this possible?  Also if this is not the correct way to do decision logic to do this any experience on how to do it greatly appreciated. 

<decision name="validcontent" >
        <event type="node-enter">
             <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
             <script>
                <variable name="validcontent" access="read,write"/>
                <variable name="bpm_package" access="read"/>
                <variable name="storeid" access="read"/>
                <expression>
                 
                      logger.log("Compare Store ID - " + bpm_package.getStoreId());
                     
                     //  for (var i = 0; i &lt; avm.stores.length; i++) {
                    //      var store=avm.stores;
                    //       
                    //        if(bpm_package.getStoreId() == store.id){
                    //            logger.log("******************Store ID ——->"+ store.id);
                   //         }
                   //   }
                     
                      var store = avm.lookupStore(bpm_package.getStoreId());
                      if(store!=null){
                        var storeRootNode = avm.lookupStoreRoot(args["store"]);
                     logger.log("store root node" +storeRootNode);
                   if (storeRootNode != null)
                     {
                        var path = storeRootNode.path + "/ROOT/dealer";
                       logger.log(+path);
                       var node = avm.lookupNode(path);
                       logger.log("node" +node);
                     }
                   }                          }   
               logger.log("In Validcontent");
               logger.log("Store ID - " + bpm_package.getStoreId());
               
               validcontent = "false";
                </expression>
             </script>
         </action>
      </event>
        <transition to="end" name="reject">
         <condition>#{validcontent == "false"}</condition>
        </transition>
      <transition to="onapprove" name="approved"></transition>
    </decision>
   
Regards
1 REPLY 1

boneill
Star Contributor
Star Contributor
I got to a solution on this for anyone else who needs this.

var wfStoreNoderef = bpm_package.getStoreId();

                     
                      logger.log("****** WF Store NodeRefID (storeid) - " + wfStoreNoderef);
                     
                      var wp = webprojects.getWebProject(wfStoreNoderef.split('–')[0]);
                      var sb = wp.getSandbox(wfStoreNoderef);

The funny thing is that using avm.lookupStore(wfStoreNoderef); does not work for the workflow sandbox.  That really threw me.

Another important thing I found when doing this work is that avm.lookupStore() and wp.getSandbox() does not return the same type of object.  They both basically return a store object so I assumed I could access the same methods, for example getAsset().  This is not the case though.  Being from an OO background I found this really weird.