<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Passing string parameter to action in folder rules in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86350#M26115</link>
    <description>&lt;P&gt;Hi all.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a Java class that extends&amp;nbsp;ActionExecuterAbstractBase and exposes some properties (String values) through setters (in this example setApprovedText) that can be set.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I registered it in a service-context.xml like this example:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;&amp;lt;bean &lt;/SPAN&gt;&lt;SPAN&gt;id&lt;/SPAN&gt;&lt;SPAN&gt;="approve-document-action"&lt;BR /&gt;&lt;/SPAN&gt;     &lt;SPAN&gt;class&lt;/SPAN&gt;&lt;SPAN&gt;="com.alfresco.ApproveDocument"&lt;BR /&gt;&lt;/SPAN&gt;     &lt;SPAN&gt;parent&lt;/SPAN&gt;&lt;SPAN&gt;="action-executer"&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;   &amp;lt;property &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;="serviceRegistry" &lt;/SPAN&gt;&lt;SPAN&gt;ref&lt;/SPAN&gt;&lt;SPAN&gt;="ServiceRegistry"&lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;   &amp;lt;property &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;="nodeService" &lt;/SPAN&gt;&lt;SPAN&gt;ref&lt;/SPAN&gt;&lt;SPAN&gt;="NodeService" &lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;   &amp;lt;property &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;="publicAction"&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;      &amp;lt;value&amp;gt;&lt;/SPAN&gt;true&lt;SPAN&gt;&amp;lt;/value&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;   &amp;lt;/property&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;   &amp;lt;property &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;="approvedText" &lt;/SPAN&gt;&lt;SPAN&gt;value&lt;/SPAN&gt;&lt;SPAN&gt;="${digitalsign.approvedtext}" &lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;/bean&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Then I can register this value in alfresco-global.properties&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;digitalsign.approvedtext&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;APPROVED &lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;This all works fine, but in some cases is would be much better if I could provide this value as an action rule parameter.&lt;/P&gt;&lt;P&gt;Basically when I create rule on a folder, and when I choose action to perform, I would like to have field where I could provide this parameter value. Is this possible, and if yes - how can it be done?&lt;/P&gt;</description>
    <pubDate>Thu, 01 Oct 2020 15:01:24 GMT</pubDate>
    <dc:creator>mmrvelj</dc:creator>
    <dc:date>2020-10-01T15:01:24Z</dc:date>
    <item>
      <title>Passing string parameter to action in folder rules</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86350#M26115</link>
      <description>&lt;P&gt;Hi all.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a Java class that extends&amp;nbsp;ActionExecuterAbstractBase and exposes some properties (String values) through setters (in this example setApprovedText) that can be set.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I registered it in a service-context.xml like this example:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;&amp;lt;bean &lt;/SPAN&gt;&lt;SPAN&gt;id&lt;/SPAN&gt;&lt;SPAN&gt;="approve-document-action"&lt;BR /&gt;&lt;/SPAN&gt;     &lt;SPAN&gt;class&lt;/SPAN&gt;&lt;SPAN&gt;="com.alfresco.ApproveDocument"&lt;BR /&gt;&lt;/SPAN&gt;     &lt;SPAN&gt;parent&lt;/SPAN&gt;&lt;SPAN&gt;="action-executer"&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;   &amp;lt;property &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;="serviceRegistry" &lt;/SPAN&gt;&lt;SPAN&gt;ref&lt;/SPAN&gt;&lt;SPAN&gt;="ServiceRegistry"&lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;   &amp;lt;property &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;="nodeService" &lt;/SPAN&gt;&lt;SPAN&gt;ref&lt;/SPAN&gt;&lt;SPAN&gt;="NodeService" &lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;   &amp;lt;property &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;="publicAction"&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;      &amp;lt;value&amp;gt;&lt;/SPAN&gt;true&lt;SPAN&gt;&amp;lt;/value&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;   &amp;lt;/property&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;   &amp;lt;property &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;="approvedText" &lt;/SPAN&gt;&lt;SPAN&gt;value&lt;/SPAN&gt;&lt;SPAN&gt;="${digitalsign.approvedtext}" &lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;/bean&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Then I can register this value in alfresco-global.properties&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;digitalsign.approvedtext&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;APPROVED &lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;This all works fine, but in some cases is would be much better if I could provide this value as an action rule parameter.&lt;/P&gt;&lt;P&gt;Basically when I create rule on a folder, and when I choose action to perform, I would like to have field where I could provide this parameter value. Is this possible, and if yes - how can it be done?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 15:01:24 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86350#M26115</guid>
      <dc:creator>mmrvelj</dc:creator>
      <dc:date>2020-10-01T15:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Passing string parameter to action in folder rules</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86351#M26116</link>
      <description>&lt;P&gt;You can do that by implementing 'org.alfresco.repo.action.ParameterizedItemAbstractBase.&lt;A href="https://github.com/Alfresco/alfresco-repository/blob/alfresco-repository-6.8/src/main/java/org/alfresco/repo/action/ParameterizedItemAbstractBase.java#L105" target="_blank" rel="noopener nofollow noreferrer"&gt;addParameterDefinitions&lt;/A&gt;(List&amp;lt;ParameterDefinition&amp;gt;)' method&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/Alfresco/alfresco-repository/blob/alfresco-repository-6.8/src/main/java/org/alfresco/repo/action/executer/ActionExecuterAbstractBase.java" target="_blank" rel="noopener nofollow noreferrer"&gt;ActionExecuterAbstractBase&lt;/A&gt; extends another abstract class :&amp;nbsp;org.alfresco.repo.action.&lt;A href="https://github.com/Alfresco/alfresco-repository/blob/alfresco-repository-6.8/src/main/java/org/alfresco/repo/action/ParameterizedItemAbstractBase.java" target="_blank" rel="noopener nofollow noreferrer"&gt;ParameterizedItemAbstractBase&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;ParameterizedItemAbstractBase provides an abstract method for providing option to add params to the action.&lt;/P&gt;
&lt;P&gt;Here is an example of action class that can get a parameter.&lt;/P&gt;
&lt;PRE&gt;public class UpdateCommentsActionDemo extends ActionExecuterAbstractBase {

	private static final String PARAM_COMMENT = "comment";
	
	private transient final NodeService nodeService;

	public UpdateCommentsAction(final ServiceRegistry serviceRegistry) {
		super();
		nodeService = serviceRegistry.getNodeService();
	}

	@Override
	protected void executeImpl(final Action action, final NodeRef actionedUponNodeRef) {
		if (nodeService.exists(actionedUponNodeRef)) {
&lt;STRONG&gt;			final String commentValue = (String) &lt;A href="https://github.com/Alfresco/alfresco-repository/blob/alfresco-repository-6.8/src/main/java/org/alfresco/service/cmr/action/ParameterizedItem.java#L61" target="_blank" rel="noopener nofollow noreferrer"&gt;action.getParameterValue&lt;/A&gt;(PARAM_COMMENT);
&lt;/STRONG&gt;			final Map&amp;lt;QName, Serializable&amp;gt; properties = nodeService.getProperties(actionedUponNodeRef);
			if (StringUtils.isNotBlank(commentValue)) {
				properties.put(DemoContentModel.CommentableAspect.Prop.COMMENTS, commentValue);
			}

			if (nodeService.hasAspect(actionedUponNodeRef,
					DemoContentModel.CommentableAspect.ASPECT)) {
				nodeService.setProperties(actionedUponNodeRef, properties);
			} else {
				nodeService.addAspect(actionedUponNodeRef,
						DemoContentModel.CommentableAspect.ASPECT, properties);
			}
		}
	}
	
	&lt;STRONG&gt;@Override
	protected void addParameterDefinitions(final List&amp;lt;ParameterDefinition&amp;gt; paramDefinitions) {
		paramDefinitions.add(new ParameterDefinitionImpl(PARAM_COMMENT, DataTypeDefinition.TEXT,
				true, PARAM_COMMENT)); 
	}&lt;/STRONG&gt;
}
&lt;/PRE&gt;
&lt;P&gt;After implementing &lt;STRONG&gt;addParameterDefinition &lt;/STRONG&gt;method, you can remove the property value which you are getting from global properties, and setup the rule to pass the value from there.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommed to go through this doc as well :&amp;nbsp;&lt;A href="https://docs.alfresco.com/6.0/references/dev-extension-points-actions.html" target="_blank" rel="nofollow noopener noreferrer"&gt;https://docs.alfresco.com/6.0/references/dev-extension-points-actions.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 15:20:18 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86351#M26116</guid>
      <dc:creator>abhinavmishra14</dc:creator>
      <dc:date>2020-10-01T15:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Passing string parameter to action in folder rules</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86352#M26117</link>
      <description>&lt;P&gt;Thank you , this works great!&lt;/P&gt;&lt;P&gt;However, I am still struglling with the last part - label of the field. Basically I cannot get the proper text to be displayed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to put in &lt;EM&gt;.properties&lt;/EM&gt; file:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;comment=My comment&lt;BR /&gt;approve-document-action.comment=My comment&lt;BR /&gt;approve-document-action.comment.display-label=My comment&lt;BR /&gt;approve-document-action.comment.title=My comment&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;However no matter what I tried - I never get "&lt;SPAN&gt;My comment&lt;/SPAN&gt;", but instead, I only get&amp;nbsp; "comment" for the label.&lt;/P&gt;&lt;P&gt;I also noticed in many examples that registration of parameter looks like this:&lt;/P&gt;&lt;PRE&gt;paramDefinitions.add(new ParameterDefinitionImpl(PARAM_COMMENT, DataTypeDefinition.TEXT,
				true, &lt;STRONG&gt;&lt;SPAN class="pln"&gt;getParamDisplayLabel&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class="pun"&gt;(&lt;/SPAN&gt;PARAM_COMMENT))); &lt;/PRE&gt;&lt;P&gt;when I use &lt;STRONG&gt;getParamDisplayLabel&lt;/STRONG&gt;(PARAM_COMMENT), I don't get anything. also I notice that this function is supposed to return something like &lt;STRONG&gt;bean-name.param-name.display-label&lt;/STRONG&gt;, but when I print it out, it returns&amp;nbsp;&lt;STRONG&gt;null.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;What am I missing?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2020 14:32:01 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86352#M26117</guid>
      <dc:creator>mmrvelj</dc:creator>
      <dc:date>2020-10-02T14:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: Passing string parameter to action in folder rules</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86353#M26118</link>
      <description>&lt;P&gt;Not exatcly sure how you have setup. Mostly likely your 'messages' (e.g. &lt;SPAN&gt;action&lt;/SPAN&gt;-messages.properties) which has the labels defined, are not getting loaded by the time action class bean is initialized and 'addParameterDefinitions' method is inovked. By default bean scope is singleton, hence spring container initializes them at application startup time, so it depends how you have defined beans in the context file.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Try these steps, i am updating the method provided earlier:&lt;/U&gt;&lt;/P&gt;
&lt;PRE&gt;@Override
protected void addParameterDefinitions(final List&amp;lt;ParameterDefinition&amp;gt; paramDefinitions) {
	paramDefinitions.add(new ParameterDefinitionImpl(PARAM_COMMENT, DataTypeDefinition.TEXT,
			true, &lt;A href="https://github.com/Alfresco/alfresco-repository/blob/alfresco-repository-6.8/src/main/java/org/alfresco/repo/action/ParameterizedItemAbstractBase.java#L197" target="_blank" rel="noopener nofollow noreferrer"&gt;&lt;STRONG&gt;getParamDisplayLabel(PARAM_COMMENT)&lt;/STRONG&gt;&lt;/A&gt;)); 
}&lt;/PRE&gt;
&lt;P&gt;When &lt;A href="https://github.com/Alfresco/alfresco-repository/blob/alfresco-repository-6.8/src/main/java/org/alfresco/repo/action/ParameterizedItemAbstractBase.java#L197" target="_blank" rel="noopener nofollow noreferrer"&gt;getParamDisplayLabel&lt;/A&gt; method is called, it will try to load the label using I18NUtil, see the method impl below:&lt;/P&gt;
&lt;PRE&gt;protected String getParamDisplayLabel(String paramName) {&lt;BR /&gt;  //&amp;lt;actionName&amp;gt;.&amp;lt;paramName&amp;gt;.display-label&lt;BR /&gt;  //e.g. update-comments.comment.display-label
  return I18NUtil.getMessage(this.name + "." + paramName + "." + DISPLAY_LABEL);
}&lt;/PRE&gt;
&lt;P&gt;&lt;U&gt;Add the labels as necessary, example:&lt;/U&gt;&lt;/P&gt;
&lt;PRE&gt;#This is used to show param label&lt;BR /&gt;update-comments.comment.display-label=A Comment&lt;BR /&gt;#This is used to show Action tile/name in the actions list in rule configuration
update-comments.title=Update Comments&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;Now most importantly, make sure that message resource bundle bean is initialized in first place then all actions etc., See the details&amp;nbsp;&lt;A href="https://github.com/Alfresco/alfresco-repository/blob/alfresco-repository-6.8/src/main/resources/alfresco/action-services-context.xml" target="_self" rel="nofollow noopener noreferrer"&gt;here&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;e.g.&lt;/P&gt;
&lt;PRE&gt;&amp;lt;bean id="com.demo.resourceBundle" class="org.alfresco.i18n.ResourceBundleBootstrapComponent"&amp;gt;
  &amp;lt;property name="resourceBundles"&amp;gt;
     &amp;lt;list&amp;gt;
        &amp;lt;value&amp;gt;alfresco/module/${project.artifactId}/messages/action-messages&amp;lt;/value&amp;gt;
     &amp;lt;/list&amp;gt;
  &amp;lt;/property&amp;gt;
&amp;lt;/bean&amp;gt;

&amp;lt;bean id="update-comments" class="com.demo.action.UpdateCommentsActionDemo" parent="action-executer"&amp;gt;
   &amp;lt;property name="publicAction"&amp;gt;
     &amp;lt;value&amp;gt;true&amp;lt;/value&amp;gt;
   &amp;lt;/property&amp;gt;
   &amp;lt;constructor-arg ref="ServiceRegistry" /&amp;gt;
&amp;lt;/bean&amp;gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Oct 2020 21:59:32 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86353#M26118</guid>
      <dc:creator>abhinavmishra14</dc:creator>
      <dc:date>2020-10-02T21:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: Passing string parameter to action in folder rules</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86354#M26119</link>
      <description>&lt;P&gt;This works perfectly. I was registering the beans before resources were loaded. It was sufficient to reorder xml file to have the .properties file load before, just as you explained.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 07:51:41 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86354#M26119</guid>
      <dc:creator>mmrvelj</dc:creator>
      <dc:date>2020-10-05T07:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Passing string parameter to action in folder rules</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86355#M26120</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/31051"&gt;@mmrvelj&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Great that it's now working - thanks for the update, helpful to other users.&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 10:53:27 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86355#M26120</guid>
      <dc:creator>EddieMay</dc:creator>
      <dc:date>2020-10-05T10:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Passing string parameter to action in folder rules</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86356#M26121</link>
      <description>&lt;P&gt;Good to hear that it worked for you. Happy coding.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 14:08:21 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/passing-string-parameter-to-action-in-folder-rules/m-p/86356#M26121</guid>
      <dc:creator>abhinavmishra14</dc:creator>
      <dc:date>2020-10-05T14:08:21Z</dc:date>
    </item>
  </channel>
</rss>

