cancel
Showing results for 
Search instead for 
Did you mean: 

How to get properties which are defined in Aspect by .js

richard_tsai
Champ in-the-making
Champ in-the-making
Hi!
   I have a requirement to send notification to users by document creator setting. Thus, I create an aspect to store subscribeUsers and an rule to send email by property subscribeUsers.
   My question is how can I get properties which are defined in custom aspect by javascript?
I tried get property like the following
   document.properties.subscribeUsers
   document.properties["subscribeUsers"]
   document.properties["htckm:subscribeUsers"]
However, I just get null value from them.
   Is anyone know how to get my aspect properties in document and how to iterate all properties in document? It seems document.properties.length could return correct number of properties.
   BTW, is there better solution on this?

Thanks Smiley Happy
7 REPLIES 7

kevinr
Star Contributor
Star Contributor
Assuming the namespace for your custom model is 'htckm' and the property on the custom aspect is called 'subscribeUsers' then the third call is correct:

document.properties["htckm:subscribeUsers"]

I assume you have checked that the document has the aspect applied? You can use the document.hasAspect("htckm:myaspectname") call as appropriate.

The value will be null if the property does not exist or has no value.

Thanks,

Kevin

richard_tsai
Champ in-the-making
Champ in-the-making
Dear Kevin,
     Thanks so much for your prompt reply.
I am sure the document has been applied aspect htckm:aspectCasestudy. However, I still got null value by invoking document.properties["htckm:subscribeUsers"]. I tried to run the javascript action after document created by web ui. It returned me correct data and email has been sent.
     BTW, I tried to seperate to apply aspect and to execute javascript into two rules. It still returned me null value.

Assuming the namespace for your custom model is 'htckm' and the property on the custom aspect is called 'subscribeUsers' then the third call is correct:

document.properties["htckm:subscribeUsers"]

I assume you have checked that the document has the aspect applied? You can use the document.hasAspect("htckm:myaspectname") call as appropriate.

The value will be null if the property does not exist or has no value.

Thanks,

Kevin

kevinr
Star Contributor
Star Contributor
If it still returns null then the property has not been set. Can you post the whole script? Does the property appear in the details page for the doc if you configure it to appear?

Thanks,

Kevin

richard_tsai
Champ in-the-making
Champ in-the-making
Dear Kevin,
      Please refer to my javascript. The property is able to display in detailed page. It's the same result as manually run action on the document  by Web UI. If it's the better to have model file for reference, I can post it tomorrow(sorry, I'm not in my company now).

Thanks again.

Richard

//==================================
// notifyUser.js
//==================================
// create mail action
  var mail = actions.create("mail");
  mail.parameters.to = "richard_tsai@xxx.com";
  mail.parameters.subject = "Hello from JavaScript: " + document.properties["name"];
  mail.parameters.from = "admin@xxx.com";
  mail.parameters.text = "hello! js test: {ext.htc.km}subscribeUsers=" + document.properties["{ext.htc.km}subscribeUsers"]
                       + "\nhtckm:subscribeUsers=" + document.properties["htckm:subscribeUsers"]
                       + "\naspect=" + document.hasAspect("htckm:aspectCasestudy");
           
                      
  // execute action against a document   
  mail.execute(document);

kevinr
Star Contributor
Star Contributor
Yes we'll need to see the model to check this. I assume 'htckm' is the shortname of the namespace uri you are using?

Thanks,

Kevin

richard_tsai
Champ in-the-making
Champ in-the-making
Dear Kevin,
     Please refer to my xml configurations.
I wonder if it's the similar case as
http://forums.alfresco.com/viewtopic.php?t=3690&sid=0992bb74b727af0d4629eadee74f409f

Thanks!

Richard

//==========================================
// Received email by javascript
//==========================================
Subject: Hello from JavaScript: filename.xls
Content:
hello! js test: {ext.htc.km}project2=null
htckmSmiley Tongueroject2=null
aspect=true

//==========================================
// htckmModel.xml
//==========================================
<?xml version="1.0" encoding="UTF-8"?>
<model name="htckm:htckmmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
   <description>HTC custom Model</description>
   <author></author>
   <version>1.0</version>
   <imports>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
   </imports>
   <namespaces>
      <namespace uri="ext.htc.km" prefix="htckm"/>
   </namespaces>
    <constraints>
       <constraint name="htckmSmiley Tonguerojects" type="LIST">
          <parameter name="allowedValues">
             <list>
                <value>A001</value>
                <value>A002</value>
                <value>A003</value>
             </list>
          </parameter>
       </constraint>
    </constraints>
    <aspects>
      <aspect name="htckm:aspectCasestudy">
         <title>HTC Case Study</title>
         <properties>
            <property name="htckm:case2">
               <title>HTC Case</title>
               <type>d:text</type>
               <mandatory>true</mandatory>
            </property>
            <property name="htckmSmiley Tongueroject2">
                <title>HTC Project</title>
               <type>d:text</type>
               <constraints>
                  <constraint ref="htckmSmiley Tonguerojects" />
               </constraints>               
            </property>
            <property name="htckm:subscribeUsers">
               <title>Subscribe Users</title>
               <type>d:text</type>
            </property>
            <property name="htckmSmiley TongueublishedDate2">
               <title>Published Date</title>
               <type>d:datetime</type>
            </property>
            <property name="htckm:authorisedBy2">
               <title>Authorized By</title>
               <type>d:text</type>
            </property>
         </properties>
      </aspect>
   </aspects>
</model>

//==========================================
// web-client-config-custom.xml
//==========================================
   <config evaluator="aspect-name" condition="htckm:aspectCasestudy">
      <property-sheet>
         <show-property name="htckm:case2"/>
         <show-property name="htckmSmiley Tongueroject2"/>
         <show-property name="htckm:subscribeUsers"/>
         <show-property name="htckmSmiley TongueublishedDate2"/>
         <show-property name="htckm:authorisedBy2"/>
      </property-sheet>
   </config>
   <config evaluator="string-compare" condition="Action Wizards">
      <aspects>
         <aspect name="htckm:aspectCasestudy"/>
      </aspects>
   </config>

richard_tsai
Champ in-the-making
Champ in-the-making
Hi! Kevin,
    I think I know why it didn't work. The rules were executed after document created. However, my custom property was filled in the next page which was after document created. I guess I should sent email in Update event.
Thanks!

Richard