Check aspects in server js webscript
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2016 09:37 AM
Hi,
Is it possible to list or check the aspects of a node in server webscript (js) ? if yes how
Thanks
Jamil
Is it possible to list or check the aspects of a node in server webscript (js) ? if yes how
Thanks
Jamil
Labels:
- Labels:
-
Archive
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2016 06:17 PM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2016 05:52 AM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2016 11:17 AM
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:
Display ${isTitled?string} in the corresponding ftl file and you'll see that it is available
Regards
Steven
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 rootvar 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
