can I assign foundset to a global?

In my solution, I have to lookup a record and refer to it often throughout the solution. I never need to display the record, just refer to it in code. I would like NOT to create a form for this purpose so I use

var FS = databaseManager.getFoundSet('server','table')

and I select the record in that foundset.

Question:

Would it be safe to assign the foundset object to a global? Would the foundset persist for the duration of the solution session?

If so, would it be safer to use a JavaScript global like this:

globalFS = databaseManager.getFoundSet('server','table')

or a Servoy global dataprovider?

Is your use of the record read-only, or do you modify and save changes to it in the course of your solutions normal activities?

g.

Yes. :)

What I mean is, I’d be interested in knowing the answer in each of those scenarios.

Well, can I dodge the question slightly?

What you’re suggesting may well work, but I don’t think it would be a good idea. If the foundset hangs around, it’s got to stay tied in to data broadcasting, and that’s probably not a very good thing performance wise. That’s an assumption, it might not work that way.

I would use a global relation to access that record. An example would be a “preferences” table, that just has one record, and a set of fields with preference values that get used throughout the app. Setup a global relation from a global var that’s set to “1” or something like that, to the preferences table record with id = 1, and then throughout your app you can just refer to the relation for that record, like “preferences.prefName” (where “preferences” is the name of the relation).

If it’s a read-only situation, you could also build a global javascript object that’s not bound to a record or foundset at solution startup and access that for values, also.

Make sense?

greg.

Thanks for your reply Greg.

You are right, the global relation would work well once I’ve identified the id of the record I want (which for SAS reasons I’d rather not hard-code into my solution)

For the read-only scenario with the global, non-bound javascript object, if you have time, can you show how you would create that object? I’m assuming there’s a way to have all the object’s properties match the record’s column names & values without having to hardcode all those properties in a declaration.

That was a great presentation you gave at the VUG by the way.

amcgilly:
Thanks for your reply Greg.

No problem.

You are right, the global relation would work well once I’ve identified the id of the record I want (which for SAS reasons I’d rather not hard-code into my solution)

I still think that’s the way to go, just find the right record at solution startup and place that ID in the proper global var for the relation to work.

For the read-only scenario with the global, non-bound javascript object, if you have time, can you show how you would create that object? I’m assuming there’s a way to have all the object’s properties match the record’s column names & values without having to hardcode all those properties in a declaration.

Try this…

var rec = // get your record object from the foundset
obj = new Object();

for(var item in rec)
{
   obj[item] = rec[item];
}

// now you can reference the values...
obj.fieldName;
obj[fieldName];

That was a great presentation you gave at the VUG by the way.

Thanks, glad you liked it! :slight_smile:

greg.

You should be able to store a foundset in a global variable, no problem.

Wether you store a foundset in a global or create a global relation referencing the specific record gives you the same result.

I cannot think of any down or upsides either way.

But, as allready suggested: when the data of the record is static (ie doesn’t change during the session), you are better off placing the data in a global object for further reference.

Paul