Issue with defining a Dynamic Participant Step with an ECMA Script | Community
Skip to main content
October 16, 2015
Solved

Issue with defining a Dynamic Participant Step with an ECMA Script

  • October 16, 2015
  • 5 replies
  • 1401 views

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. 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by WillMc1

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

5 replies

October 16, 2015

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 

October 16, 2015

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

Sham_HC
Level 10
October 16, 2015

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")

smacdonald2008
Level 10
October 16, 2015

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

WillMc1Adobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

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