Page 1 of 1

Default value SQL in Text object works only on some forms

Posted: Wed Jan 22, 2014 5:00 am
by crush
Hi,

On simple forms--forms without lookups or subforms, I have Text objects with the Default value SQL field filled. The default value shows up fine. On more complicated forms, the very same fields' default values won't show up.

I'm sorry this is so vague, but I don't know what information might be helpful.

Any idea what could be causing this?

Thank you,
Cassidy

Re: Default value SQL in Text object works only on some form

Posted: Wed Jan 22, 2014 7:59 pm
by massiws
Cassidy,
crush wrote:... but I don't know what information might be helpful.
maybe, table schema and/or the SQL code (right and wrong) might be helpful.

Re: Default value SQL in Text object works only on some form

Posted: Thu Jan 23, 2014 11:57 pm
by crush
And the plot thickens...

It isn't the form that dictates if the value will show up. Turns out, if shows up on new entries, but not entries that already exist. Doesn't matter what the SQL is. I used

Code: Select all

SELECT 'foo'[/SQL] in a Text object, FYI.

Any ideas why this is? Or how to get around it?

Re: Default value SQL in Text object works only on some form

Posted: Fri Jan 24, 2014 12:59 am
by massiws
Cassidy,
on text objects Defult Value SQL is executed only when a new record is created.
If you open an existing record this SQL isn't executed, also if the field is empty.

If you want to fill a empty text field on existing records you could use javascript/jQuery in Custom Code > Javascript nuLoadThis() function.
Another way, insert SQL in Text object > All tab > SQL Run Before Display

Hope this make sense.

Re: Default value SQL in Text object works only on some form

Posted: Fri Jan 24, 2014 1:52 am
by crush
Thank you Max for that clarification.

Let's develop the SQL Run Before Display method. So say I want 'foo' to display in a text field every time the form is loaded. Just putting

Code: Select all

SELECT 'foo'
into SQL Run Before Display doesn't do the trick. I know this is easy to do with nuLoadThis(), but I want to know how to do it with SQL Run Before Display to do more advance stuff.

What would I have to do?

Re: Default value SQL in Text object works only on some form

Posted: Fri Jan 24, 2014 3:27 pm
by massiws
Cassidy,
I have explained myself badly: in SQL Run Before Display field you can specify SQL statement(s) that are run before object is created.
You can create a temp file, update other tables, use hash variables, or whatever you want, but the result is not displayed on the object.

For some usage examples execute this SQL on samplenufinancial database:

Code: Select all

SELECT * FROM `zzsys_object` WHERE `sob_all_sql_run_before_display` <> ''
I hope I have been more clear.
Max