Hash values in Default

Hash values in Default

Postby johnbertell » Thu Apr 24, 2014 5:49 pm

I have problem to use hash values in a Default Value SQL. I try to use this:
Code: Select all
SELECT vop_timezones_id FROM voyageports
WHERE voyageports_id='#recordID#'

But it does not pick up the value.
But if I test with the real value as this:
Code: Select all
SELECT vop_timezones_id FROM voyageports
WHERE voyageports_id='153395cc60afe4'

Then it picks up the value.
John
johnbertell
 
Posts: 14
Joined: Thu Oct 24, 2013 2:02 pm

Re: Hash values in Default

Postby ians » Sun Apr 27, 2014 4:38 pm

I am new to nuBuilder but according to the current documentation, the hash variable is #RECORD_ID# i.e. with an underscore.
ians
 
Posts: 9
Joined: Sun Apr 27, 2014 4:35 pm

Re: Hash values in Default

Postby massiws » Mon Apr 28, 2014 10:43 pm

John,
what type of object are you using?
The sentence in "Default value SQL" field is valuated to populate a field only when you insert a new record: when you open an exixting record this SQL is ignored.
The hash variable #recordID# is the id of the current record, but when inserting a new record this is always '-1'.

In your case,
Code: Select all
SELECT vop_timezones_id FROM voyageports WHERE voyageports_id='#recordID#'
is valuated as
Code: Select all
SELECT vop_timezones_id FROM voyageports WHERE voyageports_id='-1'

If you want to display a value from another table you might want to use a Display object.

Hope this helps,
Max


@ians: #recordID# or #id# work in nuBuilder 2; #RECORD_ID# works in nuBuilderPro.
massiws
 
Posts: 503
Joined: Thu May 24, 2012 9:38 am
Location: Milan, Italy

Re: Hash values in Default

Postby ians » Tue Apr 29, 2014 7:49 am

John,

Thanks for the correction. Still learning :roll:
ians
 
Posts: 9
Joined: Sun Apr 27, 2014 4:35 pm

Re: Hash values in Default

Postby ians » Tue Apr 29, 2014 7:50 am

Sorry, meant Max, not John. :(
ians
 
Posts: 9
Joined: Sun Apr 27, 2014 4:35 pm

Re: Hash values in Default

Postby johnbertell » Wed Apr 30, 2014 12:47 am

Sorry, forgot some details...
It is in a subform i try to put a default value which is based on a SELECT statement including the main form's recordID. So the ID exist, and the rows in the subform are new records. So in theory it should work. I will put up some practical examples.
John
johnbertell
 
Posts: 14
Joined: Thu Oct 24, 2013 2:02 pm

Re: Hash values in Default

Postby massiws » Thu May 01, 2014 7:57 am

John, in a subform #recordID# or #id# is the id of the current record in the subform (for new records always equal to '-1').
massiws
 
Posts: 503
Joined: Thu May 24, 2012 9:38 am
Location: Milan, Italy

Re: Hash values in Default

Postby johnbertell » Mon May 05, 2014 1:49 pm

Oh, then I am a bit confused. Because I successfully use #recordID# in the SQL statement for the dropdown, and then it definitely takes the id of the main record. But in the Default SQL it apparently uses the id of the subform record.
John
johnbertell
 
Posts: 14
Joined: Thu Oct 24, 2013 2:02 pm

Re: Hash values in Default

Postby johnbertell » Wed May 07, 2014 4:45 am

dump.tiff
dump.tiff (76.32 KiB) Viewed 9877 times

Here is the example where I use the same select statement to populate the dropdown, and then just limit to 1 to always default to the first value in the list, but it does not work the way I expected. In the dropdown statement it uses the main record's id, but in the default it uses the id of the sub-row, which is always -1 since it is only used on new rows.
So I made something like this instead and call it on nuLoadThis
Code: Select all
function defaultCurr(vsubform,curr) {
    var sub_row = Array();
    sub_row = nuSubformRowArray(vsubform);
    for(var i = 0 ; i < sub_row.length; i++) {   
       var vfield=document.getElementById(sub_row[i]+'ii_currencies_id');
       //if value is not set, put a default value
       if (vfield.value=='') {
            vfield.value = curr;
        }
    }
}
johnbertell
 
Posts: 14
Joined: Thu Oct 24, 2013 2:02 pm


Return to General