Reputation: 421
I have the following function in OrientDB studio, the functions saved with no problem:
var entities= db.query("select Name from F__Entity_Master");
getTemplate(0);
function getTemplate(index){
if (index >= entities.length){
return entities;
} else {
var sql = "select from F__Subjects where subjectCode='"+ entities[index]['@class']+"'";
var template = db.query(sql);
entities[index]['template']= template;
index += 1;
getTemplate(index);
}
}
Running the function in studio generates the following error:
Erroronparsingscriptatposition#0: ErroronexecutionofthescriptScript: GetEntities------^sun.org.mozilla.javascript.internal.EvaluatorException: Javaclass"com.orientechnologies.orient.core.record.impl.ODocument"hasnopublicinstancefieldormethodnamed"template".(#12)inatlinenumber12Javaclass"com.orientechnologies.orient.core.record.impl.ODocument"hasnopublicinstancefieldormethodnamed"template".(#12)
I used recursion to avoid using null values before fetching data from database. Using for loop generates similar error.
There are no relations between F__Subjects and F__Entity_Master as for every F__Subjects record a relevant class named with subjectCode field of F__Subjects record is generated and inherited from the F__Entity_Master. So the only way to detect relation is to use the subjectCode field to get the class meta information from he F__Subjects class.
Any ideas?
Solved I used Lvca hint and here is the correct version of the function after few trials:
var entities= db.query("select from F__Entity_Master");
getTemplate(0);
return entities
function getTemplate(i){
if (i >= entities.length){
return ;
} else {
var sql = "select from F__Subjects where subjectCode='"+ entities[i].getClassName()+"'";
var template = db.query(sql);
entities[i].field('template', template[0].toMap());
i += 1;
getTemplate(i);
}
}
Upvotes: 0
Views: 618
Reputation: 533
try field.getProperty()
this worked for me when writing functions in javascript for the orientdb server
Upvotes: 0
Reputation: 9060
entities is an array of ODocument, so to get/set a field you should use respectively the field(name)
and field(name,value)
methods.
Upvotes: 1