pnature

How to set document aspect property cm:person

Blog Post created by pnature on Jan 30, 2018

I am using Alfresco community version: 5.2.0 (r135134-b14)

If you have document with aspect containing cm:person property.

   <aspects>
      <aspect name="ad:approveDocument">
            <title>Approver for Approve document</title>
            <associations>
              <association name="ad:approver">
                <title>Assignee</title>
                <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
                </source>
                <target>
                  <class>cm:person</class>
                  <mandatory>false</mandatory>
                  <many>false</many>
                </target>
              </association>

                                 ...

When you start workflow on document with this aspect I can read property ad:approver

When you want to set property ad:approver you have to

private static final String adNamespace = "http://www.namespace.com/model/approveDocument";

ServiceRegistry serviceRegistry = (ServiceRegistry)registeredBeans.get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);

NodeRef docref= serviceRegistry.getNodeService().getChildAssocs(packagenode).get(0).getChildRef();

String username = "myUser";

NodeRef person = personService.getPerson(username);

nodeService.setAssociations(docref, QName.createQName(adNamespace, "approver"), Arrays.asList(person));

Outcomes