Expand my Community achievements bar.

SOLVED

Issue with defining a Dynamic Participant Step with an ECMA Script

Avatar

Level 2

Hi, 

I am trying to provide an implementation for dynamic participant step 
using an ECMA script. The script basically returns a participant user 
based on the path of the payload.Here is the script  - 

function getParticipant() { 
    var workflowData = workItem.getWorkflowData(); 
    if (workflowData.getPayloadType() == "JCR_PATH") { 
        var path = workflowData.getPayload().toString(); 
        log.debug("this is the payload path : " + path); 
        if (path.indexOf("/content/test/a") == 0) { 
                return new String("user-a"); 
        } 
        else if (path.indexOf("/content/test/b") == 0) { 
                return new String("user-b"); 
        } 
        else if (path.indexOf("/content/test/c") == 0) { 
                return new String("user-c"); 
        } 
        else if (path.indexOf("/content/test/d") == 0) { 
                return new String("user-d"); 
        } 
        else if (path.indexOf("/content/test/e") == 0) { 
                return new String("user-e"); 
        } 
    } 


But running this script gives below exception - 

25.01.2012 16:41:26.139 *WARN* [127.0.0.1 [1327527685905] POST /etc/ 
workflow/instances HTTP/1.1] 
com.day.cq.workflow.impl.advance.DynamicParticipantNodeHandler Unable 
to get the java object java.lang.NoSuchMethodException: 
org.mozilla.javascript.NativeString.unwrap() 
                at java.lang.Class.getDeclaredMethod(Unknown Source) 
                at 
com.day.cq.workflow.impl.advance.DynamicParticipantNodeHandler.getJavaObject(DynamicParticipantNodeHandler.java: 
202) 
                at 
com.day.cq.workflow.impl.advance.DynamicParticipantNodeHandler.getParticipant(DynamicParticipantNodeHandler.java: 
156) 
                at 
com.day.cq.workflow.impl.advance.ParticipantNodeHandler.doTransition(ParticipantNodeHandler.java: 
124) 

Any pointers would be greatly appriciated. 
Thanks in advance. 

1 Accepted Solution

Avatar

Correct answer by
Employee

hi,

Not sure if this is exactly your issue, but the "new String" part will not work in your script.  Remember that this is script, not pure Java.  The best thing to do is just return quoted values like "user-a" instead of new String("user-a");

If you want to create a new string with the new operator you should be able to do it with:

new Packages.lang.java.String("user-a");

 

Will

View solution in original post

5 Replies

Avatar

Correct answer by
Employee

hi,

Not sure if this is exactly your issue, but the "new String" part will not work in your script.  Remember that this is script, not pure Java.  The best thing to do is just return quoted values like "user-a" instead of new String("user-a");

If you want to create a new string with the new operator you should be able to do it with:

new Packages.lang.java.String("user-a");

 

Will

Avatar

Level 10

For your example -- did you create it or did you reference it from an article or doc topic? 

Avatar

Level 10

Documentation request has been placed to update. For now use like [1] & also make sure to have else block in your code to return default value for unhandled case.

[1]   return new Packages.java.lang.String("user-a")

Avatar

Level 2

Hi Will ,

Thanks a lot for checking out my post . I tried returning the quoted values  still im getting the same error . 

Please check the below script 

function getParticipant() { var workflowData = workItem.getWorkflowData(); if (workflowData.getPayloadType() == "JCR_PATH") { var path = workflowData.getPayload().toString(); if (path.indexOf("/content/geometrixx/en") == 0) { return "admin"; } else { return "author"; } } }

The got the above script from the following link 

http://helpx.adobe.com/experience-manager/kb/HowToAssignAWorkflowDynamicallyToParticipants.html

Avatar

Level 2

I have created a workflow model where in the admin needs to assign the workflow task to an author . The workflow task has to be assigned to an user based on certain condition dynamically . I tried using the below package from adobe site but still its not working . 

http://helpx.adobe.com/experience-manager/kb/HowToAssignAWorkflowDynamicallyToParticipants.html