Page 1 of 1
Hash values in Default
Posted: Thu Apr 24, 2014 10:19 am
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
Re: Hash values in Default
Posted: Sun Apr 27, 2014 9:08 am
by ians
I am new to nuBuilder but according to the current documentation, the hash variable is #RECORD_ID# i.e. with an underscore.
Re: Hash values in Default
Posted: Mon Apr 28, 2014 3:13 pm
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.
Re: Hash values in Default
Posted: Tue Apr 29, 2014 12:19 am
by ians
John,
Thanks for the correction. Still learning
Re: Hash values in Default
Posted: Tue Apr 29, 2014 12:20 am
by ians
Sorry, meant Max, not John.
Re: Hash values in Default
Posted: Tue Apr 29, 2014 5:17 pm
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
Re: Hash values in Default
Posted: Thu May 01, 2014 12:27 am
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').
Re: Hash values in Default
Posted: Mon May 05, 2014 6:19 am
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
Re: Hash values in Default
Posted: Tue May 06, 2014 9:15 pm
by johnbertell
- dump.tiff (76.32 KiB) Viewed 18306 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;
}
}
}