Wednesday 18 September 2013

Returning output values from action in Alfresco

Welcome everyone ! First of all thank you for your time visiting this post. I hope this post will help you get the solution you are looking for.

Okay, Let me start now.

Generally in alfresco, we invoke an action to process certain task and we do not return any output from the action. This is a general implementation you might have done.

Consider a scenario wherein you need to return output from your action for further processing (say for example, you have to invoke another action which should have input as the output NodeRef from your first action, you might need to use the output from your action to invoke another webscript).

Here is the implementation detail about how to achieve this.

Implementation -
1. Firstly, set up output value in your Action class -

   In your ActionExecuter class - in the executeImpl method - Once you are done with your processing and you got the required output, then as shown below set up a result parameter.

   ruleAction.setParameterValue("output-value", resultNodeRef.getId());

2. Secondly, Retrieving output value of the action from where you have invoked the action.

   Scenario-1 - If you have invoked your action from javascript based webscript then below is the code snippet to retrieve the output value from the action.

     var actionOne = actions.create("your-custom-action");

     actionOne.execute(inputNode);

     logger.log("Output from the action : " + actionOne.parameters["output-value"]);
  
   Scenario-2 - If you have invoked action from java code then below is the code snippet to retrieve the output value from the action.
    
    Action action = actionService.createAction("your-custom-action");

    actionService.executeAction(action, node.getNodeRef());
    
    System.out.println(action.getParameterValue("output-value"));

Yay ! It's done. Coding done ! Time to test now ! please test it. It should work fine.

Hope this help you.

Thanks,
Ramesh C