cancel
Showing results for 
Search instead for 
Did you mean: 

Run js script with cron from scheduled-jobs-context.xml

svetlingulev
Champ in-the-making
Champ in-the-making
hi,

i have a .js script that a want to run every 1 hour.
I am following this tutorial http://aboutalfresco.blogspot.com/2010/01/scheduled-actions-in-alfresco.html
I've read about Scheduled Actions and i have some questions:
1. The file scheduled-jobs-context.xml must be put in tomcat/shared/alfresco/classes/extension directory right? And from there it will do its job?
2. The js script that i want the cron to run is called "hello.get.js" and it is located in Company Home > Data Dictionary > Web Scripts > org > alfresco > test
and according to the tutorial that i`m following this should be ${selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:hello.get.js"' )} , right ?




best regards
4 REPLIES 4

sujaypillai
Confirmed Champ
Confirmed Champ
Check out the file - <strong>"scheduled-action-services-context.xml.sample"</strong> under <strong>tomcat\shared\classes\alfresco\extension</strong>. Rename it to scheduled-action-services-context.xml and check out for various sample jobs in it. After adding/modifying you bean definition restart the server to make the changes reflect.

kaynezhang
World-Class Innovator
World-Class Innovator
1. Yes ,scheduled-jobs-context.xml must be put in tomcat/shared/alfresco/classes/extension folder.it will trigger the quartz job you configured in CronScheduledQueryBasedTemplateActionDefinition class.
2.If the scrip you want to run located in
 Company Home > Data Dictionary > Web Scripts > org > alfresco > test 
you should write it like

<!–note that after alfresco 4.0,  freemarker  entries must be escaped–>
<value>\$\{selectSingleNode('workspace://SpacesStore', 'lucene','PATH:"/app:company_home/app:dictionary/cm:webscripts/cm:org/cm:alfresco/cm:test/cm:hello.get.js"')\}</value>

By the way why not put your js into
  Company Home > Data Dictionary > scripts

kaynezhang, thanks
i have put my js file in Company Home > Data Dictionary > scripts
but an error is rised


and here is my javacript code in file createsite.js
var sitePreset = "site-dashboard";
     var shortName = "helloworld";
     var title = "Hello World";
     var description = "The Hello World site!";
     var visibility = siteService.PUBLIC_SITE;
var myNewSite = siteService.createSite(sitePreset, shortName, title, description,   visibility);


svetlingulev
Champ in-the-making
Champ in-the-making
the problem is resolved. I used the Script Action Example at the end of this page https://wiki.alfresco.com/wiki/Scheduled_Actions
and just changed the place and the name of the script.