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;
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.
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.
There are two options to achieve what you want. The first one: <javascript> var originalUser = people.getPerson("user1"); var delegateeUserName; if(originalUser.hasAspect("alvexocrgchartMember")) { if(originalUser.properties["alvexocutOfOffice"] == 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.
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.