search.findNode error

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

search.findNode error

Hi,

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

Java function uses getPerson() method from PersonService Class:

@Autowired
private AuthorityService authorityService;
@Override
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)
execution.setVariable("wfvd_patients",node);

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
Highlighted
Master

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.

Highlighted
Established Member II

Re: search.findNode error

Hi,

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)
//execution.setVariable("wfvd_patients",node);
logger.log("validation-documed.js mainValidationSecretaire -NEW wfvd_patients => " +execution.getVariable("wfvd_patients"));
}
else
{
var patientSelectione = task.getVariable('wfvd_patients');
logger.log("validation-documed.js mainValidationSecretaire - patientSelectione => " + patientSelectione);
idPatient = patientSelectione.properties["os:idPatient"];
logger.log("validation-documed.js mainValidationSecretaire - os:idPatient => " +patientSelectione.properties["os:idPatient"]);
nomPatient = patientSelectione.properties["cm:lastName"];
logger.log("validation-documed.js mainValidationSecretaire - cm:lastName => " +patientSelectione.properties["cm:lastName"]);
PrenomPatient = patientSelectione.properties["cm:firstName"];
logger.log("validation-documed.js mainValidationSecretaire - cm:firstName => " +patientSelectione.properties["cm:firstName"]);
dateNaissance = patientSelectione.properties["os:dateNaissance"];
logger.log("validation-documed.js mainValidationSecretaire - os:dateNaissance => " +patientSelectione.properties["os:dateNaissance"]);
execution.setVariable("wfvd_patients" ,task.getVariable("wfvd_patients"));
}

And this is result :

picker

validation-documed.js mainValidationSecretaire - patientSelectione => Node Type: {http://www.alfresco.org/model/content/1.0}person, Node Aspects: [{http://www.alfresco.org/model/content/1.0}ownable, {http://www.alfresco.org/model/system/1.0}cascadeUpdate, {http://www.opensolution.com/model/content/1.0}patient, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/system/1.0}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

Highlighted
Master

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.