Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Hash values in Default

Post Reply
johnbertell
Posts: 14
Joined: Thu Oct 24, 2013 6:32 am

Hash values in Default

Unread post by johnbertell »

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
ians
Posts: 9
Joined: Sun Apr 27, 2014 9:05 am

Re: Hash values in Default

Unread post by ians »

I am new to nuBuilder but according to the current documentation, the hash variable is #RECORD_ID# i.e. with an underscore.
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Hash values in Default

Unread post by massiws »

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.
ians
Posts: 9
Joined: Sun Apr 27, 2014 9:05 am

Re: Hash values in Default

Unread post by ians »

John,

Thanks for the correction. Still learning :roll:
ians
Posts: 9
Joined: Sun Apr 27, 2014 9:05 am

Re: Hash values in Default

Unread post by ians »

Sorry, meant Max, not John. :(
johnbertell
Posts: 14
Joined: Thu Oct 24, 2013 6:32 am

Re: Hash values in Default

Unread post by johnbertell »

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
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Hash values in Default

Unread post by massiws »

John, in a subform #recordID# or #id# is the id of the current record in the subform (for new records always equal to '-1').
johnbertell
Posts: 14
Joined: Thu Oct 24, 2013 6:32 am

Re: Hash values in Default

Unread post by johnbertell »

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 6:32 am

Re: Hash values in Default

Unread post by johnbertell »

dump.tiff
dump.tiff (76.32 KiB) Viewed 18139 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;
        }
    }
}
Post Reply