Sites root-scoped javascript variable not defined.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2011 08:00 AM
Greetings,
I'm attempting to modify the Share footer webscript to include some information found in an aspect applied to each site.
The javascript API docs show that there is a root scoped variable 'sites' that gives access to the sites service. My code below fails on the use of that root scoped variable with the error that it is not defined.
Any thoughts on what I'm missing? Why is sites undefined when it's supposed to be a root scoped variable? How else should I be getting the site's scriptNode from its shortName?
I'm attempting to modify the Share footer webscript to include some information found in an aspect applied to each site.
The javascript API docs show that there is a root scoped variable 'sites' that gives access to the sites service. My code below fails on the use of that root scoped variable with the error that it is not defined.
Any thoughts on what I'm missing? Why is sites undefined when it's supposed to be a root scoped variable? How else should I be getting the site's scriptNode from its shortName?
function main(){ profile = context.properties["site-profile"] if(profile){ mySite = sites.getSite(profile.shortName); //fails here… mySiteNode = mySite.node; if(mySiteNode){ if(mySiteNode.hasAspect("ac:siteProps")){ model.siteSponsor = mySiteNode.properties["ac:sponsor"]; } else{ //aspect not applied. } } }}main();
Labels:
- Labels:
-
Archive
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2011 08:18 AM
It's because the "sites" root object is only present on the Repository tier (/alfresco) and not the Web tier (/share). Share is a remote webapp that communicates with the Repository via JSON-based REST APIs.
You'll need to build a webscript on the repo tier to return the information you need. You can use the remote.call() function in the footer's JavaScript controller to make the call. Look throughout the Share source code for many examples of this pattern.
Thanks,
Mike
You'll need to build a webscript on the repo tier to return the information you need. You can use the remote.call() function in the footer's JavaScript controller to make the call. Look throughout the Share source code for many examples of this pattern.
Thanks,
Mike

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2011 08:48 AM
Understood. Thank you.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2011 10:16 AM
Mike, I seem to be getting the same thing on the alfresco side:
Message: 07240016 Wrapped Exception (with status template): 07240040 Failed to execute script '/org/aeroCOMPASS/getSiteProps.get.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)': 07240039 ReferenceError: "sites" is not defined. (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/org/aeroCOMPASS/getSiteProps.get.js#4)
Exception: org.mozilla.javascript.EcmaError - ReferenceError: "sites" is not defined. (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/org/aeroCOMPASS/getSiteProps.get.js#4)
var sitename = url.templateArgs["shortName"];if(sitename){ mySite = sites.getSite(sitename); mySiteNode = mySite.node; if(mySiteNode){ if(mySiteNode.hasAspect("ac:siteOwner")){ model.siteOwner = mySiteNode.properties["ac:sponsor"]; model.siteSponsor = mySiteNode.properties["ac:sponsor"]; } } else{ }}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2011 10:30 AM
Ah sorry -didn't spot you were using "sites" - try "siteService"
Thanks,
Mike
Thanks,
Mike

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2012 10:28 PM
Does that mean that the existing Wiki documentation e.g. on http://wiki.alfresco.com/wiki/4.0_JavaScript_API#Root_Scope_Objects and http://wiki.alfresco.com/wiki/4.0_JavaScript_Services_API#Get_list_of_site_members is incorrect ?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2012 10:27 AM
No, it's just that those only apply on the Repository tier. I admit that's not particular clear from those pages. Please do feel free to edit them if you think that needs clarifying.
Thanks,
Mike
Thanks,
Mike
