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

cbosdonnat
Champ in-the-making
Champ in-the-making
Hi,

could you show us the contents of the included script ? Are you sure that your included script isn't missing the character ";" somewhere ?

briboe
Champ in-the-making
Champ in-the-making
I found the issue.  I originally thought the error was caused by the import statement but it wasn't.  An errant space found its way into the util.js in one of my var definitions.  That was causing the error.  Not sure how that happened since I copied a working script.  Must have fat fingered somehwere Smiley Surprisedops: .  Thanks cbosdonnat for looking at the post.

krithika123
Champ in-the-making
Champ in-the-making
hi

i have a similar issue

i tried doing <import resource="classpath:alfresco/extension/templates/gbs/pvtbankingspace/pvtbanking.js"> mentioned in the api cookbook but got an error saying
:: org.mozilla.javascript.EvaluatorException - syntax error (AlfrescoScript#14)

My webscript is :
<import resource="classpath:alfresco/extension/templates/gbs/pvtbankingspace/pvtbanking.js">
var sectionName;
for each (field in formdata.fields)
{
    if (field.name == "sectionName")
    {
        sectionName = field.value;
    }
}

sectionName=""+sectionName;
sectionName=sectionName.replace(eval(/ /g),"_");

createFolder(pvtBankingPath, sectionName);
createFolder(pvtBankingSharedPath, sectionName);

model.sectionName=sectionName;

function createFolder(parentPath, newNodeName){
    var parentNode=companyhome.childByNamePath(parentPath);
    var _newNode = parentNode.createFolder(newNodeName);
    _newNode.save();
}
though it showed me error while compiling i deployed it thinking it would work .Could u please help me out with this problem.

mikeh
Star Contributor
Star Contributor
Your problem is unlikely to do with the <import> statement as the runtime reports the problem at line #14. As the runtime includes code lines in imported files, you need to either post that too, or work out which is line 14 yourself after concatenating the files together.

Mike

krithika123
Champ in-the-making
Champ in-the-making
hi mike ,

thanks a lot but could u please refer this
http://forums.alfresco.com/en/viewtopic.php?f=36&t=14614&p=47999&hilit=importing+javascript#p47999
I guess there are no updates on the same issue and i am facing a similar problem.I have tried all the options mentioned in this post but none of them is working.Please revert back.

mikeh
Star Contributor
Star Contributor
As I said before, I don't think your problem is with the import statement, but with whatever in your code is at line #14.
syntax error (AlfrescoScript#14)

You need to find out exactly what statement is at that line by either posting the contents of pvtbanking.js or telling us how many code lines it contains (if it's more than 14 then the error is there).

I suggest pasting the contents of that file into your main webscript in place of the import statement and checking the code works as expected.

Mike

krithika123
Champ in-the-making
Champ in-the-making
hi mike,
My code works absolutely fine when i paste the contents of the file "pvtbanking.js" in my webscript but fails in the import statement .The syntax problem it shows me is on the if condition in the above mentioned script but i dont think anything is wrong with that.Basically i wanted to load and read the contents from the js since i have to reuse the values again and again.I wanted a way out to do this and saw one of the Alfresco's Api's offering the import statement.But there was an issue when i did that.Please give me a way out to this problem.

mikeh
Star Contributor
Star Contributor
This format definitely works:
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action-sets.lib.js">

Make sure you've got the leading "/" and the full path.

Mike

krithika123
Champ in-the-making
Champ in-the-making
Hi mike,

Thank you for your inputs.However i used "<import resource="classpath:alfresco/extension/templates/webscripts/it/sella/intranet/dmservice/pvtbankingspace/pvtbanking.js">"  without the "/" before alfresco which worked perfectly well.

I tried using "/" as u had said "<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action-sets.lib.js">"
and the full path but it did not work.