cancel
Showing results for 
Search instead for 
Did you mean: 

Check aspects in server js webscript

jamilnour
Star Contributor
Star Contributor
Hi,

Is it possible to list or check the aspects of a node in server webscript (js) ? if yes how

Thanks
Jamil
3 REPLIES 3

steven_okennedy
Star Contributor
Star Contributor
Hi Jamil,

The SciptNode object that represents a Node in javascript has various properties for listing the aspects currently applied to that node including
<ul>
<li>aspects< - lists the apects with fully qualified names/li>
<li>aspectsShort - lists the aspects with short prefixes e.g. cm:titled</li>
</ul>

There's also a method called hasAspect(strAspectName) which will give you a true/false check for a particular aspect on that node.

Have a look at http://docs.alfresco.com/5.1/references/API-JS-ScriptNode.html

Regards

Steven

Hi Steven,

Ok, aspects and aspectsShort can be used on the server webscript tier which is my question.

But hasAspect is a client-side JS function which can't be used on the webscript tier

Best regards
Jamil

steven_okennedy
Star Contributor
Star Contributor
Hi Jamil,

Alfresco's Javascript API (as per http://docs.alfresco.com/5.1/references/API-JS-ScriptNode.html) is a server side API available on the repository server tier.  This is not a client side javascript API. If you have access to a ScriptNode object from within your server side script, you will have access to the hasAspect(str) method on that object as well as the aspects and aspectsShort properties. 

If you have any doubts on this look at the source of ScriptNode.java (https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/repository/source/ja...) which is actually what the Rhino javascript engine that Alfresco uses is actually giving you back.

Alternatively, you could always write a quick script that uses it, e.g. I just did a very quick modification to the controller of the default sample webscript "folder.get.js" in the Data Dictionary/Web Scripts folder in the repository:

// locate folder by path
// NOTE: only supports path beneath company home, not from root
var folder = roothome.childByNamePath(url.extension);
if (folder == undefined || !folder.isContainer)
{
      status.code = 404;
   status.message = "Folder " + url.extension + " not found.";
   status.redirect = true;
}
model.folder = folder;
model.isTitled = folder.hasAspect("cm:title")


Display ${isTitled?string} in the corresponding ftl file and you'll see that it is available

Regards

Steven