Accessing Aspects with JavaScript

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2007 08:16 PM
<aspects>
<aspect name="custom:Reviewers">
<title>Reviewers</title>
<properties>
<property name="custom:Reviewer1">
<title>Reviewer1</title>
<type>d:text</type>
</property>
<property name="custom:Reviewer2">
<title>Reviewer2</title>
<type>d:text</type>
</property>
<property name="custom:Reviewer3">
<title>Reviewer3</title>
<type>d:text</type>
</property>
</properties>
</aspect>
</aspects>
The aspect appears as it should and I can add reviewers to documents with no problem. I would like to write a script that accesses these reviewers and sends emails to them when the document is moved to a certain space.
document.hasAspect("custom:Reviewers") returns true as it should but document.aspects.length is undefined as is document.aspects.properties.
document.aspects.size() returns 6 but I can't step through the aspects with document.aspects.properties since document.aspects.properties is undefined. I can get an iterator with
var docAspects = document.aspects;
var it = docAspects.iterator();
but it.next() doesn't seem to return anything I can use. One of the objects returned with it.next() does have a toString() that returns "{custom.model}Reviewers" but it.next().properties is undefined.
What am I missing?
Thanks in advance.
- Labels:
-
Archive

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2007 06:15 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2007 09:43 AM
Are you using Alfresco 2.1?
Yes.
It looks like document.aspects returns a Java HashSet but the objects returned by an iterator do not have the properties defined in the aspect, Reviewers. There is no such thing as casting in JavaScript, right?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2007 10:52 AM
You can retrieve properties (defined by an aspect) using the standard doc.properties collection.
e.g. reviewer = document.properties["custom:Reviewers"];

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2007 12:48 PM
document.properties returns an array of length 17. When I step through the array:
var propertyAccumulator;
for(i=0; i<l; i++)
{
s = new String(document.properties);
if(s != null && s.indexOf("Reviewer") >= 0)
{
name = s;
}
propertyAccumulator = propertyAccumulator + " " + s;
}
where l = document.properties.length, s is always null. If instead of s = new String(document.properties) I do s = document.properties.toString() I get an error that says "can't call method toString() on null," of course (just trying to cover all bases here).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2007 08:08 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2007 06:23 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2007 09:27 AM
Although the aspect may be applied, it's possible the property has not been set. You can inspect any node in the repository using the node browser (http://localhost:8080/alfresco/faces/jsp/admin/store-browser.jsp) - take a look at your node in question.
In the content model you can assign a default value to any property - if you do, the property is set on the node at creation time.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2007 07:59 PM
I have defined a content rule for the "Company Home > Pending Publication > Submissions > In Progress > Under Review" space that is applied to incoming documents that have the Reviewers aspect. This rule executes a JavaScript file. However, when I copy a document which has the "Reviewers" aspect and has had values entered for the Reviewer1, Reviewer2 and Reviewer3 properties into the "Under Review" space, in this JavaScript code even though document.hasAspect("custom.Reviewers") returns true, document.properties["custom:Reviewers"] returns null and document.aspects["custom:Reviewers"] is undefined.
If I need to set the property, how do I do it? The Node Browser has been of no help. Its results are pretty much meaningless to me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2007 06:52 AM
I don't know if the property (which property?) has been set.
The property you're trying to access!!!
What are the names of your properties?
custom:Reviewer1
custom:Reviewer2
custom:Reviewer3
So, try
document.properties["custom:Reviewer1"]
or
document.properties["custom:Reviewer2"]
or
document.properties["custom:Reviewer3"]
