Getting org.restlet.Component.BonitaRestletApplication Exception or error caught in server resource

Hi,
I trying sending email to human task candidates user, and tried this codes:
1.
import org.ow2.bonita.util.AccessorUtil def candidates = AccessorUtil.getQueryRuntimeAPI().getTaskCandidates(activityInstance.getUUID()) def to=“” for(user in candidates){ if(to!=“”) to+=“,” // If Emails are not stored in Bonita User Experience, please adapt the next line to get email from your system to+=AccessorUtil.getIdentityAPI().getUser(user).getEmail() } return to

import org.bonitasoft.engine.api.ProcessRuntimeAPI;
import java.util.logging.Logger;
import java.lang.StringBuilder;

import org.bonitasoft.engine.api.IdentityAPI;
import org.bonitasoft.engine.identity.ContactData;

int dI = 0;
boolean debug = true;
StringBuilder logWrite = new StringBuilder();
Logger logger = Logger.getLogger(“org.bonitasoft”);

ProcessRuntimeAPI processRuntimeAPI = apiAccessor.getProcessAPI();
logWrite.append(“\n\n”);

//set the name of the routine
logWrite.append("Process Name: "+ processRuntimeAPI.getProcessInstance(processInstanceId).getName());

logWrite.append(“\n\t” + dI++ + “Trace Start”);

//TODO - Code goes in here - START

String bonUser = “walter.bates”;
String toEmails = “”;

def identityAPI = apiAccessor.getIdentityAPI();
def theUser = apiAccessor.getIdentityAPI().getUserByUserName(bonUser.toLowerCase());
if(theUser!=null){

logWrite.append(“\n\t” + dI++ + “contact found”);

// To have professional email
ContactData professionalData = identityAPI.getUserContactData(theUser.getId(), false);
String professionalEmail = professionalData.getEmail();

if (professionalEmail != null && !professionalEmail.isEmpty()) {

logWrite.append(“\n\t” + dI++ + “professionalEmail: “+professionalEmail);
toEmails = professionalEmail;
logWrite.append(”\n\t” + dI++ + toEmails);
}
else{
logWrite.append(“\n\t” + dI++ + “contact NOT found”);
return “contact NOT found”;
}
}

logWrite.append(“\n\t” + dI++ + “Trace End”);
logWrite.append(“\n\n”);
if(debug){logger.severe(logWrite.toString())}

return toEmails;


So this is my problem, I am getting below error repeatedly for every solution:

org.restlet.Component.BonitaRestletApplication Exception or error caught in server resource
org.bonitasoft.engine.bpm.process.ProcessInstanceNotFoundException: USERNAME=***** | Archived Process Instance not found [TASK ID]

and I stuck here please guide me.
Thank you all.

The Groovy Script expression fails at execution:

  • You should see error stack traces in the Engine logs (from the Studio: Help-> Bonita Engine log)
  • You are using V5 packages (org.ow2.) instead of V6/7 ones (org.bonitasoft.)
  • You should use the provided variable “apiAccessor” to access the Bonita APIs
  • Javadoc is available here

Could you specify what version of Bonita you are using? The first code looks like version 5 which is super (super) old.

Also, could you tell us where you run this code from in the process (connector, operation, expression, process scope, task scope)?

I am using Bonita 7.7.3, I just found codes in this community and have no idea for which version code has been written.
I add the code on a task Execution tab in connector in for messaging (email smtp) and added it in script(groovy) for To attribute, but error confusing and it cause a human task in user portal does not appear in Task and instead it goes to Open Task tab and status goes red (error).
Here is some screenshots.
[Portal overview ]: https://pasteboard.co/HHBnRNp.png
![Portal overview ][Por tal overview ]

< ![Task connector][Task connector] !-- Images →
[Task connector]: https://cdn.pbrd.co/images/HHBmUZ8.png

![Connector ][Connector ]
[Connector ]: https://cdn.pbrd.co/images/HHBnjIb.png

A Tip on displaying CODE/LOGS correctly in Posts:

You can use the Supplied Buttons above, <> and ‘<>’, for displaying code and logs or use:

Do not use the Supplied Buttons above, for some reason they refuse to work correctly, and despite bringing it to Bonitasofts attention, it’s low priority.

To Show Code/Logs correctly use

< code >
your code/log
< /code >

removing the spaces to allow the showing of code/logs correctly as here:

your code/log

You should still be able to edit your post to ensure the correct formatting of the code to help us understand it easier.

Thanks and regards
Seán

OK, I try it