Going blind

Problem: I’m attempting to trap whether the user has filled two global fields, return an error message if either is empty, proceed if both have values.

This kind of thing is dead easy in FMP. I’ve been struggling with this for hours, getting nowhere.

If ( global.field == null )

If ( field == null )

Var x = global.field;
If ( x == null )

Var x = field;
If ( x == null )

ALL of these don’t work. Assistance appreciated.

Try this:

If (globals.field == null ) //check if null

or

If (globals.field)  //check if globals.field is NOT empty or null

or

If (!globals.field) //check if globals.field is empty or null

you will also need to add ShowDialog for a true result, if you want to display a message

HJK:
Try this:

If (globals.field == null ) //check if null

or

If (globals.field) //check if globals.field is NOT empty or null

or

If (!globals.field) //check if globals.field is empty or null

Thanks, helpful.

Please clarify the difference between empty and null.

databases make differences between empty or null

For instance if you create a record en fill nothing in that field, than that field is null. If you type something and save it, and than manually delete the string you typed, than the field is empty!

HJK:
Try this:

If (globals.field == null ) //check if null

or

If (globals.field) //check if globals.field is NOT empty or null

or

If (!globals.field) //check if globals.field is empty or null

Very strange.

If (globals.field) //evaluates the same whether there’s content in the field or not. The “globals” part of the fieldname displays in green.

If (!globals.field) //also evaluates the same whether there’s content or not. However with the presence of the “!” the whole fieldname displays in black.

oke,

if(globals.field)
{
plugins.dialogs.showInfoDialog(‘Info’,‘globals.field is NOT empty!’)
}

if(!globals.field)
{
plugins.dialogs.showInfoDialog(‘Info’,‘globals.field is empty!’)
}

the green and black thing are only labels to help you. It does nothing with the code itself

HJK:
oke,

if(globals.field)
{
plugins.dialogs.showInfoDialog(‘Info’,‘globals.field is NOT empty!’)
}

if(!globals.field)
{
plugins.dialogs.showInfoDialog(‘Info’,‘globals.field is empty!’)
}

the green and black thing are only labels to help you. It does nothing with the code itself

Works, thanks.

Just one addition: you don’t need to do if (…) {} twice.

You can also do:
if (…)
{

}
else
{

}

See the samplecode for these functions under the Flow node in the Servoy Editor

Paul

Morley: for more explanation on null’s and empties: Search the forum. There has been more discussion about this. This difference is a typical “feature” of all SQL Databases

pbakker:
Just one addition: you don’t need to do if (…) {} twice.

You can also do:
if (…)
{

}
else
{

}

See the samplecode for these functions under the Flow node in the Servoy Editor

It was ment as two different methods :slight_smile:

:D

pbakker:
Just one addition: you don’t need to do if (…) {} twice.

You can also do:
if (…)
{

}
else
{

}

See the samplecode for these functions under the Flow node in the Servoy Editor

Unless I’m looking in the wrong place, samplecode is greyed out for all items under the Flow node in the Servoy Editor. I’m going to JSLib → Flow → ifelse → Move Sample.

That is the right place, do you have a method open to move the sample code to?

pbakker:
That is the right place, do you have a method open to move the sample code to?

Yes, open method. I can Move Code but not Move Sample. This is true for all items in Date, String and Flow. Math items have both enabled, but Move Sample does exactly the same thing as Move Code.

R2 2.0.3 build 276.

Same both Mac and PC.

By the way, I didn’t really get (understand) the “twice” example.

What paul means is if your statement is NOT true, then you can display a default result like the if statement in FM.

FM
If (argument, true,default result)

Servoy
if (argument)
{
True result
}
else
{
Default result
}

You can also use multiple statements:

if (argument)
{
True result
}
if else (argument)
{
True result
}
if else (argument)
{
True result
}
else
{
Default result
}

OK, I’m mixing up names again: On some Items you just hae Move code and on others you also have move SampleCode.

Sometimes the function is so simple, samplecode would just be a little bit overdoing it, don’t you think?

Paul

Ali Saleem _ Software Developer.pdf (718 KB)

pbakker:
OK, I’m mixing up names again: On some Items you just hae Move code and on others you also have move SampleCode.

Sometimes the function is so simple, samplecode would just be a little bit overdoing it, don’t you think?

Paul

Agreed.

There are times when I’m assuming things are more complicated than they actually are. Coming from FMP, all those braces look a bit intimidating at first, but really it’s just the same thing.

Starting cold, no prior JavaScript, no other “languages” than just FMP, it’s disorienting, so much to learn. Like learning to walk for the first time.