cancel
Showing results for 
Search instead for 
Did you mean: 

Understanding Script inclusion

leonardo_celati
Champ in-the-making
Champ in-the-making
Coming from s Javascript background I used to include files in html pages which have function in it to be invoked, often with parameters.

Things seems quite different with Alfresco Script (and Web Script). As it is stated in Alfresco Doc

<cite>
Scripts can also include (or "import") other scripts. The developer can build libraries of scripts that are included at runtime to reduce copy/paste between script files.
</cite>

I see many example on how to include Script file, and it works (I get no error), but I am missing how to use them from the main caller script.

A real case example: I have a working script 'RenderingScript' which retrieve a given node and creates a rendition and save its transformed file.

I wanted to create another script which retrieves a set of nodes and for each invoke the 'RenderScript'. This could be easily accomplished by encapsulating code into Javascript function, but I don't know how to do this in Alfresco, where this concept is missing (or I am missing).
3 REPLIES 3

kaynezhang
World-Class Innovator
World-Class Innovator
alfresco will recursively resolve imports in a javascript file A, and combine the scriplet in A and all the scriplets in imports file into a script string ,and send this script string to rhino engine.
For example ,you can create a utils.js file which include many utils functions and saved it in class path

Then you can include this js file into other js files and call it's function,just as import other classes in java language or include some other c header files in c language.

<import resource="classpath:com/yourclasspath/utils.js">

Thanks, the point was infact to know if the Script could contains function(), I tought this was not possible, but I was wrong as you made me notice.

By the way, just an 'academic question', can I invoke a Script from a Script rather than including it ?

No ,you can't  invoke a script from a script without including it.you can invoke a script using java .