Alfresco - 在工作流程中获取用户名

Alfresco - Get username in workflow

我在创建工作流时正在搜索 assignees 的用户名...

我用这个:

public void notify(DelegateExecution execution) {
    // get value of property mymodel:myproperty 
    Object assignees = execution.getVariable("bpm_assignees"); 
}

当我得到 bpm_assignees 我得到这个:

bpm_assignees map value: [Node Type: {alfresco.org/model/content/…}person, Node Aspects: [{alfresco.org/model/content/…}ownable, {alfresco.org/model/system/1.0}referenceable, {alfresco.org/model/system/1.0}localized], Node Type: {alfresco.org/model/content/…}person, Node Aspects: [{alfresco.org/model/content/…}ownable, {alfresco.org/model/system/1.0}referenceable, {alfresco.org/model/system/1.0}localized]]

如何获得username

这些对象是 Person NodeRefs。如果您从该节点取回属性,您将获得用户的用户名、电子邮件地址等信息。您可以查看可用的属性 by looking at the core content model(向下滚动到 cm:person)

假设返回的对象是一个ActivitiScriptNodeList, then they'll come handily wrapped up with accessors etc as they'll be ActivitiScriptNodes. Those extend the normal Alfresco JavaScript ScriptNode objects。这意味着您需要做的是:

public void notify(DelegateExecution execution){
   ActivitiScriptNodeList assignees = execution.getVariable("bpm_assignees"); 
   for (ActivitiScriptNode personNode : assignees) {
       String username = personNode.getProperties().get("cm:userName");
       String email = personNode.getProperties().get("cm:email");
       // TODO Use this
   }
}