cancel
Showing results for 
Search instead for 
Did you mean: 

Null nodeRef when running action

ardamose123
Champ on-the-rise
Champ on-the-rise
I've been developing some custom action proof of concepts. I've got to the point where I can implement an action, configure its bean, update the share-config-custom.xml file and make the action appear and show a form to collect input in Alfresco Share.

The action just returns (some day) the Levenshtein distance between two documents, with no validations about them being plain text files. However, when I run this action, I come across a problem: in my implementation of
executeImpl(Action, NodeRef)
method, the NodeRef is null, when it's supposed to be an actual NodeRef to the node being acted upon.

Can someone tell me if this is a mistake on my side or Alfresco's? I'm deploying the extension as a JAR. File contents follow.

<em>FormActionExecuter.java</em> (without Levenshtein distance code)

public class FormActionExecuter extends ActionExecuterAbstractBase {
   private ContentService contentService;
   private NodeService nodeService;
  
   public static final String PARAM_OTHER_DOC = "other-doc";
  
   public void setContentService(ContentService contentService) {
      this.contentService = contentService;
   }
  
   public void setNodeService(NodeService nodeService) {
      this.nodeService = nodeService;
   }

   @Override
   protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
      paramList.add(new ParameterDefinitionImpl(PARAM_OTHER_DOC, DataTypeDefinition.NODE_REF, true, getParamDisplayLabel(PARAM_OTHER_DOC)));
   }

   @Override
   protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
      if (!nodeService.exists(actionedUponNodeRef)) // <– IllegalArgumentException HERE
         return;
     
      NodeRef other = (NodeRef) action.getParameterValue(PARAM_OTHER_DOC);
     
      String content1 = contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT).getContentString();
      String content2 = contentService.getReader(other, ContentModel.PROP_CONTENT).getContentString();
     
      action.setParameterValue(PARAM_RESULT, Integer.valueOf(computeLevenshteinDistance(content1, content2)));
   }
}


<em>example-action-context.xml</em>

<beans>
   <bean id="org-form-bean" class="org.example.FormActionExecuter" parent="action-executer">
      <property name="contentService">
         <ref bean="ContentService" />
      </property>
      <property name="nodeService">
         <ref bean="NodeService" />
      </property>
   </bean>
</beans>


<em>share-config-custom.xml</em>

<alfresco-config>
   <config evaluator="string-compare" condition="org-form-bean">
      <forms>
         <form>
            <field-visibility>
               <show id="other-doc" />
            </field-visibility>
            <appearance>
               <field id="other-doc" label="Document to be compared"/>
            </appearance>
         </form>
      </forms>
   </config>
  
   <config evaluator="string-compare" condition="DocLibActions">
      <actions>
         <action id="org-form" type="javascript" label="Test form">
            <param name="function">onActionFormDialog</param>
            <param name="itemKind">action</param>
            <param name="itemId">org-form-bean</param>
            <param name="mode">edit</param>
            <param name="successMessage">Works!</param>
            <param name="failureMessage">Fail…</param>
         </action>
      </actions>
     
      <actionGroups>
         <actionGroup id="folder-browse">
            <action index="102" id="org-form" />
         </actionGroup>
         <actionGroup id="document-browse">
            <action index="102" id="org-form" />
         </actionGroup>        
      </actionGroups>
   </config>
</alfresco-config>
3 REPLIES 3

mluraschi
Champ in-the-making
Champ in-the-making
Hi, I ran into this post because I have the same exact problem.

Last week I created a UI action with no parameters and in share-config-custom its parameter is
<param name="function">onActionSimpleRepoAction</param>
. It works, I am able to use the
actionedUponNodeRef
inside the
executeImpl(Action, NodeRef)
method.

Yesterday, instead, I created an action with parameters and this time I used
<param name="function">onActionFormDialog</param>
. The form shows up, the parameters are passed correctly, but
actionedUponNodeRef
is
null
in
executeImpl(Action, NodeRef)
.

Any ideas? suggestions? I am struggling to find any informations about it.

Thanks

mluraschi
Champ in-the-making
Champ in-the-making
Just to let the next reader know that I solved the issue by turning the action into a webscript. I added the submission-url property to the form and make it point to my webscript, so that the form will POST to it.

Apparently, onActionSimpleRepoAction, passes the ActionedUponNodeRef, but does not handle forms, while onActionFormDialog, handles forms, but simply does not pass the ActionedUponNodeRef. I spent a whole day trying to trace it back, but it seems like it just behaves that way.

kamielvdz
Champ in-the-making
Champ in-the-making
The answer is to add the following reference to your share action config:

<param name="destination">{node.nodeRef}</param>



<action id="org-form" type="javascript" label="Test form">
            <param name="function">onActionFormDialog</param>
            <param name="itemKind">action</param>
            <param name="itemId">org-form-bean</param>
            <param name="destination">{node.nodeRef}</param>
            <param name="mode">edit</param>
            <param name="successMessage">Works!</param>
            <param name="failureMessage">Fail…</param>
         </action>


Took me a while to figure out. Destination is a badly chosen parameter name, but seems to act as actionedUponNode.