Reference Error for Relation

Version: 5.2.8 - build 1016

Code that I developed in November 2010 has been working until today when I deleted and re-created a relation named ‘animal_to_synonym’ that it uses. Now, when the code executes, it generates the following error message:

ReferenceError: “animal_to_synonym” is not defined.

Here is the line of code that generates the error:

var recordSynonym = animal_to_synonym.getRecord( animal_to_synonym.newRecord( false ) )

The relation is clearly visible in:

Solution Explorer → Modules → ARM_animal → Relations

and, when I open the relation, all the settings look good.

Here is an excerpt from the server log:

2011-06-22 16:06:07,930 ERROR [AWT-EventQueue-0] com.servoy.j2db.util.Debug - Throwable
org.mozilla.javascript.EcmaError: ReferenceError: “animal_to_synonym” is not defined. (C:\Users\kim\servoy51_workspace\ARM_animal\globals.js#228)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3663)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3657)
at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3719)
at org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1754)
at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1679)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3752)
at script.createAnimalRecord(C:\Users\kim\servoy51_workspace\ARM_animal\globals.js:228)

I have also stopped and re-started Developer several times to clear any potential problems.

Why does Servoy think the relation is not defined? Any help is very much appreciated!

Just guessing here:
Did you delete the relation from one module and create in another module?
Did you add that new module back to the solution?
Is it only in developer that you see this (I would guess that you have not exported it and tried it on a server?)
Are you certain the spelling is not changed (case change perhaps?)

is “animal_to_synonym” a global relation?
(so it only has globals on the left side of the relation?)

Hi, Tom.

Thanks for the reply.

Did you delete the relation from one module and create in another module?

No, the relation exists in within the same module.

Did you add that new module back to the solution?

The module is not new and has always been part of the solution.

Is it only in developer that you see this (I would guess that you have not exported it and tried it on a server?)

Yes, only in the Developer. I figured if I couldn’t get it to work in Developer, there was no sense in trying to get it to work with Servoy Servver.

Are you certain the spelling is not changed (case change perhaps?)

Yes, I am most certain the spelling is correct. In fact, I manually typed in the code in one test and used the automatic code insertion in a different test to eliminate the possibility of typing errors.

Hi, Johan.

is “animal_to_synonym” a global relation? (so it only has globals on the left side of the relation?)

Funny you should ask. When I recreated the relation, I did so in the ARM_animal → Globals → Relations folder, but when I saved the relation, it showed up under the ARM_animal → Relations folder. I tried this several times with the same result. Regardless in which folder the relation was created, it always shows up in the ARM_animal → Relations folder, and the ‘undefined relation’ error messasge is emitted whenever the solution is exeuted. So, I cannot say with any certainty whether the relation is global or not.

As far as the code is concerned, the method is global to the ARM_animal module, and the ‘var recordSynonym’ variable (that uses the relation) is local to the method. I am not certain I answered your question. If not, would you be so kind to give me an example?

Thanks!

if it is a global or not is simple, are on the left side only globals defined or not?

Johan,

Are you asking if the relation is prefixed with ‘globals.’ (global-dot)? If so, then the answer is no (the code I provided shows that).

But, that was my point…that I could not create a relation under the ‘globals’ node. If I tried to prefix the relation with ‘globals.’, that line of code would be flagged with an error.

By experimenting, I found that if I move the code to a form method, it works. However, if I put the code in a global method (unders the globals node), then the relation gets flagged as undefined. So, I guess my question is how to create a global method that is not attached to a form that uses relations?

Hi Kim,

A relation turns into a global relationship when you use a global variable on the left side of the relation definition.
So it has nothing to do with the name of the relationship but with the definition.

Hope this explains things.

kwpsd:
By experimenting, I found that if I move the code to a form method, it works. However, if I put the code in a global method (unders the globals node), then the relation gets flagged as undefined. So, I guess my question is how to create a global method that is not attached to a form that uses relations?

ok then the relation is not a global relation (where only global dataproviders are on the left side of the definition, as robert says it has nothing to do with the name)

But if it is not a global relation that it is a very very bad idea to just do “not_global_relation.column” in a global method!!

Because where does the data come from for that not_global_relation??
It isn’t suddenly there in a global scope! you have to give the relation to the global method or give the record which that relation is coming from like this:

form method:

function myformmethod() {
    // do something with the relation in my nice global method:
    globals.myglobalmethod(not_global_relation);
    // or     globals.myglobalmethod(arecord);
}

globals:

function myglobalmethod(rel) {
   rel.x = rel.y +1;
}

A relation turns into a global relationship when you use a global variable on the left side of the relation definition.

Thanks, Robert…that’s what I was missing. After reading your post, I checked the wiki and found it there as well. It looks like the section on relations in the wiki has been updated since I last had a look at it.

Johan, clearly, my understanding of the scope of relations was wrong, and I have one more questions about them.

I thought that the node Solution–>Globals–>Relations was the place to create a global relationship which is why I was confounded when attemping to create a new relationship (by right-clicking on the node) and saving it, the relation appeared under the node Solutions–>Relations. So, for what purpose is the node Solution–>Globals–>Relations used?

that displays just Global relations… You can do new relation through that node just fine, but then you are just in the default relation dialog, if you create a none global relation then it won’t appear in your global relation node.

The nodes are just a view on all your relations, displaying where the node (globals in this case) filters on.