search.findNode error

Showing results for 
Search instead for 
Did you mean: 
Established Member II

search.findNode error


when i create a new person, a java function is called, using the fields bellow  :

Java function uses getPerson() method from PersonService Class:

private AuthorityService authorityService;
public NodeRef createPatient(String idPatient, String nomPatient, String prenomPatient, Date dateDeNaissance) {
return personService.getPerson(userName);

But in my javascript, i need to get Node , not a nodeRef, so i use search.findNode() method like that :

var nodePat = createPatient(idPatient,PrenomPatient,nomPatient,dateNaissance);
//execution.setVariable("wfvd_patients" ,nodePat);
var node = search.findNode(nodePat)

But i get the error " org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Exception while invoking TaskListener: 02130054 Failed to execute supplied script: Passed value is not an instance of ActivitiScriptNode, cannot set variable value."

What is the best way to do it ?

Thank you

3 Replies

Re: search.findNode error

There is no out of the box API to get instances of ActivitiScriptNode in default Alfresco. In one project for a customer I built myself a custom extension of the Script API to deal with this.

Unfortunately, the scripts run inside the workflow are run as "insecure scripts", so they do not have access to the full scope of the Java interoperability features. With these features it would be possible to manually create an instance of ActivitiScriptNode even without any special API.

Established Member II

Re: search.findNode error


thank's for your reply.

Also i may be wrong, because :

- it doesn't work when i create new person

- but it works when i pick-up personn

So i have added log in javascript called by task (complete) in order to follow workflow step by step :

if(task.getVariable('wfvd_newPatient') == true)
idPatient = task.getVariable("wfvd_idPatient");
nomPatient = task.getVariable("wfvd_nomPatient");
PrenomPatient = task.getVariable("wfvd_prenomPatient");
dateNaissance = task.getVariable("wfvd_dateNaissance");

var nodePat = createPatient(idPatient,PrenomPatient,nomPatient,dateNaissance);
execution.setVariable("wfvd_patients" ,nodePat);
logger.log("validation-documed.js mainValidationSecretaire - NEW nodePat => " + nodePat);
logger.log("validation-documed.js mainValidationSecretaire - NEW idPatient => " + idPatient);
logger.log("validation-documed.js mainValidationSecretaire - NEW nomPatient => " + nomPatient);
logger.log("validation-documed.js mainValidationSecretaire - NEW PrenomPatient => " + PrenomPatient);
logger.log("validation-documed.js mainValidationSecretaire - dateNaissance => " + dateNaissance);

//var node = search.findNode(nodePat)
logger.log("validation-documed.js mainValidationSecretaire -NEW wfvd_patients => " +execution.getVariable("wfvd_patients"));
var patientSelectione = task.getVariable('wfvd_patients');
logger.log("validation-documed.js mainValidationSecretaire - patientSelectione => " + patientSelectione);
idPatient =["os:idPatient"];
logger.log("validation-documed.js mainValidationSecretaire - os:idPatient => "["os:idPatient"]);
nomPatient =["cm:lastName"];
logger.log("validation-documed.js mainValidationSecretaire - cm:lastName => "["cm:lastName"]);
PrenomPatient =["cm:firstName"];
logger.log("validation-documed.js mainValidationSecretaire - cm:firstName => "["cm:firstName"]);
dateNaissance =["os:dateNaissance"];
logger.log("validation-documed.js mainValidationSecretaire - os:dateNaissance => "["os:dateNaissance"]);
execution.setVariable("wfvd_patients" ,task.getVariable("wfvd_patients"));

And this is result :


validation-documed.js mainValidationSecretaire - patientSelectione => Node Type: {}person, Node Aspects: [{}ownable, {}cascadeUpdate, {}patient, {}referenceable, {}localized]
validation-documed.js mainValidationSecretaire - os:idPatient => 123789
validation-documed.js mainValidationSecretaire - cm:lastName => toto
validation-documed.js mainValidationSecretaire - cm:firstName => titi
validation-documed.js mainValidationSecretaire - os:dateNaissance => Fri Jan 01 00:00:00 CET 1965

New person :

validation-documed.js mainValidationSecretaire - NEW nodePat => workspace://SpacesStore/9a63089e-94de-4473-a200-a59cc5f59c8b
validation-documed.js mainValidationSecretaire - NEW idPatient => 454545
validation-documed.js mainValidationSecretaire - NEW nomPatient => nom2
validation-documed.js mainValidationSecretaire - NEW PrenomPatient => prenom2
validation-documed.js mainValidationSecretaire - dateNaissance => Tue Jul 16 00:00:00 CET 1957

To resume : when person already exists (execution.setVariable("wfvd_patients" ,task.getVariable("wfvd_patients"))Smiley Wink it works and when person doesn't exist (execution.setVariable("wfvd_patients" ,nodePat);) it doesn't work

How can i solve ? is it really Node that i need ?

Thank you


Re: search.findNode error

Yes, that is the annoying part of the workflow-related Script API. Any nodes set via the WorkflowService Java API (e.g. via Share forms) are already ActivitiScriptNode instances because the Java API parts already convert it as such. But when you are running a JavaScript listener, you are already "below" that API layer, and you need to convert any NodeRef you get (i.e. by creating a person) to an instance of that Java class yourself. You cannot do that with just JavaScript. The only way to solve this is to write yourself a small little Java-based extension of the Script API that does that conversion for you.