Using functions as lookup value

Hi,

On ServoyWorld I’ve seen a presentation how you can use funtions.

I wondered if I could use a function as a lookup value in the dataprovider definition.

I would like to use the following:

function myUUID()
{
	return application.getUUID().toString()
}

into a lookup value (UUID sequence I can’t use because Servoy handels UUID as an object and not as a string, and it is not always a primary key that I want to fill)

So I thought to create a global variable like this:

var myGlobal = function () {return application.getUUID().toString()}

and use this global as lookup value.

But in stead of an UUID in my database I see a message like “internal javascript function” in my database column.

Is what I want possible (Servoy 5.2)?

You are getting “internal javascript function” as a value, because the the lookup is using “myGlobal” as a value, not as a function…this difference would look like this in code

//As value;
var asValue = globals.myGlobal;

//As function
var asFunc = globals.myGlobal();

You should be able to select “Sequence” as the auto enter type, and choose"UUID generator" to autofill columns with a UUID.

jgarfield:
You should be able to select “Sequence” as the auto enter type, and choose"UUID generator" to autofill columns with a UUID.

Servoy doesn’t accept that because I don’t want to set the UUID flag on true.

I tried this several times, and after a certain moment Servoy is complaining that I compare a STRING with an OBJECT.
That is the reason I don’t use this UUID generator and/or UUID flag

But I’ll try your suggestion about the function. I’ll let know if this works

jgarfield:
You are getting “internal javascript function” as a value, because the the lookup is using “myGlobal” as a value, not as a function…this difference would look like this in code

//As value;

var asValue = globals.myGlobal;

//As function
var asFunc = globals.myGlobal();




This doesn't work either. Now I get an UUID from my function, but each time I add a new record, it returns the same UUID from the function, and that is not very unique <img src="{SMILIES_PATH}/icon_confused.gif" alt=":?" title="Confused" />

martinh:
Servoy doesn’t accept that because I don’t want to set the UUID flag on true.

I tried this several times, and after a certain moment Servoy is complaining that I compare a STRING with an OBJECT.

Martin,

Can you describe the scenario when Servoy complains?
I think this should work.

Btw, which version of Servoy are you using?

Rob

Hi Rob,

rgansevles:
Can you describe the scenario when Servoy complains?

It is difficult to give a scenario, because those errors didn’t came directly.
It looked to me that when such a field was used over a relation, that it showed the error.

I’ve seen same kind of issue already on the forum: http://forum.servoy.com/viewtopic.php?f=8&t=13011
It could be that I (also) used the UUID generator for a PK-field, but I need it to be used as a string and not as an object

This was the error I got:

Fout in relatie (means Error in relation)

com.servoy.j2db.dataprocessing.DataException: Unable to convert between com.servoy.j2db.util.UUID and JAVA_OBJECT.

rgansevles:
Btw, which version of Servoy are you using?

I was using 5.2.4
Since 2 days I updated to 5.2.6
I guess that doesn’t make any difference

Martin