cancel
Showing results for 
Search instead for 
Did you mean: 

Add users to a group

kbjicho
Champ in-the-making
Champ in-the-making
Hi

Somebody, anybody please help.

I want to create a workflow that will let users assign proxies/acting user if they are not in the office to work on their tasks.

I used the following script yesteday and it worked  Smiley Very Happy but today it's giving me errors and i cant figure out what went wrong between yesterday and today :shock: :


<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
    <runas>admin</runas>
        <script>
               
   var srcGrpNode=people.getGroup('GROUP_groupName);
   var authority = "User1";
   
                   if(authority)
         {
           people.addAuthority(srcGrpNode,authority);
        }
   </script>
</action>
5 REPLIES 5

hsohaib
Champ on-the-rise
Champ on-the-rise
May be Alfresco is not in the mood today Smiley Happy .

Did you correct the missing ' in :

var srcGrpNode=people.getGroup('GROUP_groupName);

kbjicho
Champ in-the-making
Champ in-the-making
Yes i did corrected it even tryed with double quotes but still i'm not getting any joy.

Please i realy need help on this one because if users cant be able to assign proxies to work on their tasks when they are out of office it means they are not going to use Alfresco workflow at all.

<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         
      <runas>admin</runas>
      <script>
                                    var srcGrpNode = people.getGroup("GROUP_droupName");
          var authority = "User1";
             if(authority)
                {
                  people.addAuthority(srcGrpNode,authority);
                }
      </script>
      </action>
            

This is a part of the error log that i get

Caused by: org.alfresco.error.AlfrescoRuntimeException: 08170002 Can't find method org.alfresco.repo.jscript.People.addAuthority(org.alfresco.repo.jscript.ScriptNode,string). (AlfrescoJS#1)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:469)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeString(RhinoScriptProcessor.java:255)
   … 129 more
Caused by: org.mozilla.javascript.EvaluatorException: Can't find method org.alfresco.repo.jscript.People.addAuthority(org.alfresco.repo.jscript.ScriptNode,string). (AlfrescoJS#1)
   at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
   at org.mozilla.javascript.Context.reportRuntimeError(Context.java:1030)
   at org.mozilla.javascript.Context.reportRuntimeError(Context.java:1086)
   at org.mozilla.javascript.Context.reportRuntimeError1(Context.java:1049)
   at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:162)
   at org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
   at org.mozilla.javascript.gen.c1._c0(AlfrescoJS:1)
   at org.mozilla.javascript.gen.c1.call(AlfrescoJS)
   at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
   at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
   at org.mozilla.javascript.gen.c1.call(AlfrescoJS)
   at org.mozilla.javascript.gen.c1.exec(AlfrescoJS)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:453)

kbjicho
Champ in-the-making
Champ in-the-making
Please guys i need help. Somebody, anybody.

If i dont get this right it means all my efforts will be in vain cause they are not going to continue using the processes i have build them.

patil
Champ on-the-rise
Champ on-the-rise
Hi,
1. Can you make sure you are using the correct username and the group name
2.Open the class org.alfresco.repo.jscript.People

/**
     * Add an authority (a user or group) to a group container as a new child
     *
     * @param parentGroup   The parent container group
     * @param authority     The authority (user or group) to add
     */
    public void addAuthority(ScriptNode parentGroup, ScriptNode authority)
    {
        ParameterCheck.mandatory("Authority", authority);
        ParameterCheck.mandatory("ParentGroup", parentGroup);
        if (parentGroup.getQNameType().equals(ContentModel.TYPE_AUTHORITY_CONTAINER))
        {
            String parentGroupName = (String)parentGroup.getProperties().get(ContentModel.PROP_AUTHORITY_NAME);
            String authorityName;
            if (authority.getQNameType().equals(ContentModel.TYPE_AUTHORITY_CONTAINER))
            {
                authorityName = (String)authority.getProperties().get(ContentModel.PROP_AUTHORITY_NAME);
            }
            else
            {
                authorityName = (String)authority.getProperties().get(ContentModel.PROP_USERNAME);
            }
            authorityService.addAuthority(parentGroupName, authorityName);
        }
    }

Put the debugger in the above lines. There you can find what is going wrong.

Thanks,
Patil
ECM Consultant

patil
Champ on-the-rise
Champ on-the-rise
Caused by: org.mozilla.javascript.EvaluatorException: Can't find method org.alfresco.repo.jscript.People.addAuthority(org.alfresco.repo.jscript.ScriptNode,string). (AlfrescoJS#1)


It says the parameter passed by you is wrong. The second parameter has to be of type ScriptNode not String according to the method definition
  /**
     * Add an authority (a user or group) to a group container as a new child
     *
     * @param parentGroup   The parent container group
     * @param authority     The authority (user or group) to add
     */
    public void addAuthority(ScriptNode parentGroup, ScriptNode authority)
    {
        ParameterCheck.mandatory("Authority", authority);
        ParameterCheck.mandatory("ParentGroup", parentGroup);
        if (parentGroup.getQNameType().equals(ContentModel.TYPE_AUTHORITY_CONTAINER))
        {
            String parentGroupName = (String)parentGroup.getProperties().get(ContentModel.PROP_AUTHORITY_NAME);
            String authorityName;
            if (authority.getQNameType().equals(ContentModel.TYPE_AUTHORITY_CONTAINER))
            {
                authorityName = (String)authority.getProperties().get(ContentModel.PROP_AUTHORITY_NAME);
            }
            else
            {
                authorityName = (String)authority.getProperties().get(ContentModel.PROP_USERNAME);
            }
            authorityService.addAuthority(parentGroupName, authorityName);
        }
    }


So what you need to do is instead of passing the username you have to pass the scriptNode of user using the method
people.getPerson(userName)

so that  the following method returns you the ScriptNode

  /**
     * Gets the Person given the username
     *
     * @param username  the username of the person to get
     * @return the person node (type cmSmiley Tongueerson) or null if no such person exists
     */
    public ScriptNode getPerson(String username)
    {
        ParameterCheck.mandatoryString("Username", username);
        ScriptNode person = null;
        if (personService.personExists(username))
        {
            NodeRef personRef = personService.getPerson(username);
            person = new ScriptNode(personRef, services, getScope());
        }
        return person;
    }

Hope it helps.

Thanks,
Patil
ECM Consultant