Reference Error for Relation

Questions, tips and tricks and techniques for scripting in Servoy

Reference Error for Relation

Postby kwpsd » Thu Jun 23, 2011 1:48 am

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:

Code: Select all
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!
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: Reference Error for Relation

Postby Thomas Parry » Thu Jun 23, 2011 3:38 am

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?)
Tom Parry
Prospect IT
Java/C++/Servoy/Jasper Reports/Simulation/Service Applications
http://www.prospect-saas.biz
Thomas Parry
 
Posts: 498
Joined: Thu Jan 10, 2008 8:48 pm
Location: Ottawa, Canada

Re: Reference Error for Relation

Postby jcompagner » Thu Jun 23, 2011 10:05 am

is "animal_to_synonym" a global relation?
(so it only has globals on the left side of the relation?)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Reference Error for Relation

Postby kwpsd » Thu Jun 23, 2011 10:53 pm

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.
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: Reference Error for Relation

Postby kwpsd » Thu Jun 23, 2011 11:11 pm

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!
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: Reference Error for Relation

Postby jcompagner » Fri Jun 24, 2011 10:26 am

if it is a global or not is simple, are on the left side only globals defined or not?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Reference Error for Relation

Postby kwpsd » Mon Jun 27, 2011 2:32 pm

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?
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: Reference Error for Relation

Postby ROCLASI » Mon Jun 27, 2011 2:49 pm

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Reference Error for Relation

Postby jcompagner » Mon Jun 27, 2011 2:57 pm

kwpsd wrote: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:

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


globals:

Code: Select all
function myglobalmethod(rel) {
   rel.x = rel.y +1;
}
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Reference Error for Relation

Postby kwpsd » Tue Jun 28, 2011 9:28 pm

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?
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: Reference Error for Relation

Postby jcompagner » Wed Jun 29, 2011 10:06 am

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.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Methods

Who is online

Users browsing this forum: No registered users and 10 guests