cancel
Showing results for 
Search instead for 
Did you mean: 

How to retrieve associations of a content type

darkredd
Star Contributor
Star Contributor
Good day,

I am trying to retrieve known associations off a type that is attached to a node using javascript. I have tried several ways that seems not to work, or perhaps I just do not know. Here is the script I am running in attempt of achieving this.

<javascript>
var originalUser = people.getPerson("vusanim");
var delegatee;

if(originalUser.hasAspect("alvexocSmiley SurprisedrgchartMember"))
{
   if(originalUser.properties["alvexocSmiley SurprisedutOfOffice"] == true)
   {
      
      delegatee = originalUser.childAssocs["alvexoc:delegation"][0].typeShort;
      logger.log(delegatee + " %%% " + delegatee.assocs["alvexoc:delegationTarget"] + " ******************** ");
   }
   else
   {
      logger.log(delegatee + " *******$$$$$$$$*******");
   }
}
else
{
   logger.log("Person is in the office ********************");
}
</javascript>

I am using alvex module as you can see, when I do a node browse of this all properties are available. As you can see I also tried the "associations()" method to no success.

How can I retrieve the associations I want from this type.
I would appreciate the help.
3 REPLIES 3

jpotts
World-Class Innovator
World-Class Innovator
I have heard of Alvex but I have not looked at its content model. Are you sure that alvexoc:delegation is a *child* association and not a *peer* association? If it is a peer association, use assocs instead of childAssocs.

Jeff

avasyukov
Champ in-the-making
Champ in-the-making
Hello.

Delegations are stored in childAssocs, but content model for them is quite tricky to support 'delegation by role' in addition to 'default delegation'. See slide 17 in http://www.slideshare.net/itdsystems/orgchart-for-alfresco-lightning-talk for details.

There are two options to achieve what you want. The first one:
<javascript>
var originalUser = people.getPerson("user1");
var delegateeUserName;

if(originalUser.hasAspect("alvexocSmiley SurprisedrgchartMember"))
{
   if(originalUser.properties["alvexocSmiley SurprisedutOfOffice"] == true)
   {
      var delegation = originalUser.childAssocs["alvexoc:delegation"][0];
      delegateeUserName = delegation.assocs["alvexoc:delegationTarget"][0].properties.userName;
      logger.log(" %%% " + delegateeUserName);
   }
   else
   {
      logger.log(delegatee + " *******$$$$$$$$*******");
   }
}
else
{
   logger.log("Person is in the office ********************");
}
</javascript>

However, I'd prefer the second option and use native Alvex root-scope object:
<javascript>
// We use orgchart.getPerson() here instead of people.getPerson()
var originalUser = orgchart.getPerson("user1");

if(originalUser.getOutOfOffice())
{
  var delegateeUser = originalUser.getDefaultDelegation().getTarget();
  logger.log( "Out of office, delegated to: " + delegateeUser.getUserName() );
}
else
{
  logger.log( "In office" );
}
</javascript>

This method is better not only because it's shorter. The point is that we (as Alvex development team) will provide API-level backward compatibility, but we can not guarantee that backend models will stay the same in the future Alvex releases.

The only thing to note about native 'orgchart' root scope object - call to orgchart.getPerson() returns JscriptOrgchartPerson object. You can take a look at https://github.com/ITDSystems/alvex/blob/master/core/orgchart/repo/src/java/com/alvexcore/repo/orgch... for methods available.

Hi avasyukov.

You solution worked like a charm. As you might have guessed, I had tried all other avenues I knew or thought of to no good; one of the attempts was very close to your solution, just lacked something.

I am very grateful for your assistance. However, option 2 does not seem to work.

Many thanks.

Regards
DarkRedd