cancel
Showing results for 
Search instead for 
Did you mean: 

Problem Importing Javascript file

briboe
Champ in-the-making
Champ in-the-making
I am trying to import a javascript file from the repository into a webscript .js.  I used the syntax from the Javascript API cookbook:

<import resource="/Company Home/Data Dictionary/Scripts/mylib.js">

It is the first line in my script and the file exsists in the repository.  However when I attempt to run the webscript I get:

Failed to execute script '/helloWorld/helloworld.get.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)': missing ; before statement (AlfrescoScript#1)

I am running 2.9c(816) on windows under tomcat.  Any help would be appreciated.
19 REPLIES 19

kevinr
Star Contributor
Star Contributor
If you get a syntax error, it means you have a JavaScript comment or similar above the import line - they *must* be first in the file as the pre-processor does not understand javascript comments (to make it simple and fast!)

Cheers,

Kev

Thanks… Your Post helped me! Smiley Happy

nicolabeghin
Champ in-the-making
Champ in-the-making
Hi
I'm following up on this thread cause it seems like it's somehow related.
I get error
04160096 Unable to locate included script classpath resource

with this first line of code in my comments-list.get.html.ftl (loaded under Repository/Webscripts, where I usually load any custom webscript)
<import resource="classpath:/alfresco/templates/org/alfresco/import/alfresco-util.js">

Is there anything wrong? I can't get around the problem, not even copying the file in the same folder cause it recursively loads other classpath-relative .js

kevinr
Star Contributor
Star Contributor
The utils file you are loading is part of Share (web-tier, different app) not Alfresco server. Which is why it hasn't been found by a webscript in Repository/Webscripts.

Kev

nicolabeghin
Champ in-the-making
Champ in-the-making
Thanks a lot kevinr for pointing out the problem. Do you have any suggestions on how to get around the problem?

I want to load (asynchronously) the properly-formatted comments list, but I'm unable to figure out what .ftl/.head.ftl I need to load to recreate all the required markup (basically: comments-list.get.html.ftl adds the call to
Alfresco.CommentsList
, but this Alfresco object is defined in the comments-list-min.js, previously included with comments-list.get.head.ftl
Any way to include files even if they are not in the same tier?


// added by comments-list.min.js
<!– Comments List –> <!– do not look at paths, they are hardcoded for testing purposes –>
   <script type="text/javascript" src="./alfresco_files/comments-list-min.js"></script>
   <style type="text/css" media="screen">
      @import "/share/res/components/comments/comments-list.css";
   </style>

// by share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/comments/comments-list.get.html.ftl
<script type="text/javascript">//<![CDATA[
      new Alfresco.CommentsList("template_x002e_comments_x002e_document-details_x0023_default").setOptions(
      {
         nodeRef: "workspace://SpacesStore/95b13a20-f175-4e8e-9244-fd75ed77e996",
         siteId: null,
         maxItems: 10,
         activity: {"itemTitle": "FILETEST2", "pageParams": {"nodeRef": "workspace:\/\/SpacesStore\/95b13a20-f175-4e8e-9244-fd75ed77e996"}, "page": "document-details"},
         editorConfig:
         {
            inline_styles: false,
            convert_fonts_to_spans: false,
            theme: "advanced",
            theme_advanced_buttons1: "bold,italic,underline,|,bullist,numlist,|,forecolor,|,undo,redo,removeformat",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_resizing: true,
            theme_advanced_buttons2: null,
            theme_advanced_buttons3: null,
            theme_advanced_path: false,
            language: "it"
         }
      }).setMessages(
         {"message.confirm.delete": "Eliminare questo commento?", "message.delete.success": "Commento eliminato", "message.wait": "Attendere…", "message.delete.failure": "Impossibile eliminare il commento", "header.edit": "Modifica commento…", "header.comments": "Commenti", "message.loadeditform.failure": "Impossibile caricare il modulo di modifica del commento", "message.noComments": "Nessun commento", "message.savecomment": "Salvataggio del commento in corso…", "message.confirm.delete.title": "Elimina commento", "button.addComment": "Aggiungi commento", "header.add": "Aggiungi commento…", "link.deleteComment": "Elimina commento", "button.save": "Salva", "label.avatar": "Avatar", "button.cancel": "Annulla", "message.savecomment.failure": "Impossibile salvare il commento", "link.editComment": "Modifica commento"}
      );

arnoldschrijve1
Champ on-the-rise
Champ on-the-rise
Hi Nicola, I created a reply to this post in the other related topic: https://forums.alfresco.com/en/viewtopic.php?f=36&t=44697&p=131553#p131553

cyr
Champ in-the-making
Champ in-the-making
I am having problems to make request in alfresco database.
I followed this tutorial: http://wiki.alfresco.com/wiki/3.4_JavaScript_API,and created a simple js file for the request.
<import resource="classpath:alfresco/extension/myutils.js">
<import resource="/Company Home/Data Dictionary/Scripts/mylib.js">

function requestSearch(){
var nodes = search.luceneSearch("TEXT:alfresco");
return nodes;
}

$(function() {

$("#articles").click( function(){
  alert( requestSearch());
});
});
with just a simple request to display alfresco text.
but it doesn't work, et when i debug an error is shown at the import of librairies.
i checked the location of theses libraries files in "/Company Home/Data Dictionary/Scripts/, but they don't exist in that location and i didn't manage to find where they are.
Does anyone know where are they located?
or am i on the wrong path?

thx!

kaynezhang
World-Class Innovator
World-Class Innovator
By your code

$(function() {

$("#articles").click( function(){
alert( requestSearch());
});
});
I gues your reqeustSearch() is client-side JavaScript .
the import command and search object should be run in server side and executed in the alfresco repository context

cyr
Champ in-the-making
Champ in-the-making
thanks,

Actually I'm pretty new to Alfresco as you can guess.

Can you clarify something for me, should I go the webscript route, and then what kind of step am I missing ?
I tried the webscripts route according to this ttutorial : http://ecmarchitect.com/alfresco-developer-series-tutorials/webscripts/tutorial/tutorial.html#what-i... ,
here is the helloworld.get.desc.xml :
<webscript>
<shortname>Hello World</shortname>
<description>Hello world web script</description>
<url>/helloworld?name={nameArgument}</url>
</webscript>

the helloworld.get.js
model.foo = "bar";

and the helloworld.get.html.ftl

Hello, ${args.name}!

Foo: ${foo}

When i try without the Foo: ${foo}, it works, but when i try with it, i get an error like:

The Web Script /alfresco/service/helloworld has responded with a status of 500 - Internal Error.

500 Description:   An error inside the HTTP server which prevented it from fulfilling the request.

Message:   03040065 Wrapped Exception (with status template): 03040100 Erreur lors du traitement du modèle 'Expression foo is undefined on line 4, column 17 in helloworld.get.html.ftl.'. Veuillez contacter votre administrateur système.

Am i missing something?
thanx in advance


kaynezhang
World-Class Innovator
World-Class Innovator
It seems there is nothing wrong with your code ,please make sure all your files are encoded using utf-8 and there is no garbled character in these files.

And for testing purpose ,I suggest you add following line <authentication>guest</authentication> to your hellowworld.get.desc.xml,like following

<webscript>
<shortname>Hello World</shortname>
<description>Hello world web script</description>
<url>/helloworld?name={nameArgument}</url>
<authentication>guest</authentication>
</webscript>