Unable to define a scheduled action in CE 5.2

cancel
Showing results for 
Search instead for 
Did you mean: 
Established Member

Unable to define a scheduled action in CE 5.2

Dear All,

I would like to create a scheduled action in Alfresco CE 5.2 which starts a js file each night. The js sript does something like this:

  • lists all the sites in the repository
  • checks the folders in the documentLibrary in each site and if a folder has a particular type and the name follows a pattern, then extracts the values of several custom properties.
  • then creates a CSV file and puts it into the documentLibrary of the site

Basically it creates a status report on folder level.

The script works when it is launched manually.

The requirement is to have this script executed each night and recreate the report file so users with no access to the individual folders can check where each change order (this is what is stored in the folders) stands.

I created - based on this site: https://www.curiousnerd.me/scheduled-custom-action-alfresco/  - the scheduled-action-services-context.xml file.

The script to run is called EDLI_RunScheduledDTMReport.js and it is stored in the /company_home/data_dictionary/scripts folder.

here is the context file:

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

<beans>

    <!--
Define the model factory used to generate object models suitable for use with freemarker templates.
-->
    <bean id="templateActionModelFactory"
          class="org.alfresco.repo.action.scheduled.FreeMarkerWithLuceneExtensionsModelFactory">
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry"/>
        </property>
    </bean>

    <!--Execute the script /Company Home/Data Dictionary/Script/exampleScript.js -->
    <bean id="runScriptAction"
          class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
        <property name="actionName">
            <value>script</value>
        </property>
        <property name="parameterTemplates">
            <map>
                <entry>
                    <key>
                        <value>script-ref</value>
                    </key>
                    <!-- Note that as of Alfresco 4.0, due to a Spring upgrade, the FreeMarker ${foo} entries must be escaped -->

                    <value>\$\{selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:EDLI_RunScheduledDTMReport.js"' )\}</value>

                    <!-- This value tag is for Alfresco 3.x, because the escape of FreeMarker entries will fail otherwise -->

                    <!--<value>#{"${"}selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:exampleScript.js"' )#{"}"}</value>-->

                </entry>
            </map>
        </property>
        <property name="templateActionModelFactory">
            <ref bean="templateActionModelFactory"/>
        </property>
        <property name="dictionaryService">
            <ref bean="DictionaryService"/>
        </property>
        <property name="actionService">
            <ref bean="ActionService"/>
        </property>
        <property name="templateService">
            <ref bean="TemplateService"/>
        </property>
    </bean>

    <!-- Script execution config -->
    <bean id="runScript"
          class="org.alfresco.repo.action.scheduled.CronScheduledQueryBasedTemplateActionDefinition">
        <property name="transactionMode">
            <value>UNTIL_FIRST_FAILURE</value>
        </property>
        <property name="compensatingActionMode">
            <value>IGNORE</value>
        </property>
        <property name="searchService">
            <ref bean="SearchService"/>
        </property>
        <property name="templateService">
            <ref bean="TemplateService"/>
        </property>
        <property name="queryLanguage">
            <value>lucene</value>
        </property>
        <property name="stores">
            <list>
                <value>workspace://SpacesStore</value>
            </list>
        </property>
        <property name="queryTemplate">
            <value>PATH:"/app:company_home/cm:customSpace"</value>
        </property>
        <!--Cron script execution every 10 minutes-->
        <property name="cronExpression">
            <!-- fire the action before midnight each workday -->
            <!-- <value>0 55 23 ? * MON,TUE,WED,THU,FRI *</value> -->
            <!-- fire the action every 30 min -->
            <value>0 0/10 * * * ?</value>
        </property>
        <property name="jobName">
            <value>RunDTMreport</value>
        </property>
        <property name="jobGroup">
            <value>jobGroup</value>
        </property>
        <property name="triggerName">
            <value>triggerD</value>
        </property>
        <property name="triggerGroup">
            <value>triggerGroup</value>
        </property>
        <property name="scheduler">
            <ref bean="schedulerFactory"/>
        </property>
        <property name="actionService">
            <ref bean="ActionService"/>
        </property>
        <property name="templateActionModelFactory">
            <ref bean="templateActionModelFactory"/>
        </property>
        <property name="templateActionDefinition">
            <ref bean="runScriptAction"/>
            <!-- This is name of the action (bean) that gets run -->
        </property>
        <property name="transactionService">
            <ref bean="TransactionService"/>
        </property>
        <property name="runAsUser">
            <value>System</value>
        </property>
    </bean>
</beans>

The cron expression is set to run in every 10 min for testing purposes.

I checked the various log files but found no information about whether the tasks is executed or not. Do I need to modify something?

Can the above context file work if the search system is not Lucene but Solr4?

Can you please help me out?

Thanks alot,

Zsolt Putnoky

3 Replies
Established Member

Re: Unable to define a scheduled action in CE 5.2

SOLVED !

The above XML has an error. When I specified the value for the "queryTemplate", I forgot to remove the custom space from the example. The working version looks like this:

 <property name="queryTemplate">
       <value>PATH:"/app:company_home"</value>
 </property>

Regards,


Zsolt Putnoky

Customer

Re: Unable to define a scheduled action in CE 5.2

Great!

For debugging, you can always use some logger.warn() in your js code for getting some execution info in your action. And you may use OOTB Support addon, to run manually the defined execution job. 

Regards.

--C.

Established Member

Re: Unable to define a scheduled action in CE 5.2

Well, this is how I found the mistake. Using JavaScript Consol - a pure marvel Smiley Happy - i left one well hidden print command somewhere by accident. As soon as I made the modification on the folder location, Alfresco throw an error, bingo, I was on the right way.

Have a good weekend,

Zsolt Putnoky