Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Changing a field value before save
-
- Posts: 49
- Joined: Thu May 03, 2018 12:08 pm
Changing a field value before save
Hi,
I am trying to change a field value in BB php section but it doesn't work.
Any idea?
--------------------------------------
$ejercicio = substr(nuHash()[opo_fecha],0,4);
$s = "select cod_oportunidad from codigo where cod_ejercicio = $ejercicio";
$t = nuRunQuery($s);
$r = db_fetch_object($t);
nuSetFormValue('opo_oportunidad', $r->cod_oportunidad); // The value in $r->cod_oportunidad is right but the field 'opo_oportunidad' doesn't get the new value.
--------------------------------------
Thanks.
I am trying to change a field value in BB php section but it doesn't work.
Any idea?
--------------------------------------
$ejercicio = substr(nuHash()[opo_fecha],0,4);
$s = "select cod_oportunidad from codigo where cod_ejercicio = $ejercicio";
$t = nuRunQuery($s);
$r = db_fetch_object($t);
nuSetFormValue('opo_oportunidad', $r->cod_oportunidad); // The value in $r->cod_oportunidad is right but the field 'opo_oportunidad' doesn't get the new value.
--------------------------------------
Thanks.
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: Changing a field value before save
Don't you mean BS (Before Save) PHP section ?ahernandez wrote:Hi,
I am trying to change a field value in BB php section but it doesn't work.
Thanks.
BTW, I don't think that values can be modified with nuSetFormValue() in BS. You probably need to modify the POST data. I'm sure Steven can tell you how to do it.
-
- Posts: 49
- Joined: Thu May 03, 2018 12:08 pm
Re: Changing a field value before save
The problem is I have to set a field value 'opo_oportunidad' in the last moment before insert the record in database and it depends of the year typed in form date field. That's why I looking the last number used for this year in the table 'codigo'. Obviously after this I have to update this record in 'codigo' as well...
-
- Posts: 49
- Joined: Thu May 03, 2018 12:08 pm
Re: Changing a field value before save
Sorry toms,
I am doing this in BS section, not in BB. It was a mistake.
I am doing this in BS section, not in BB. It was a mistake.
Re: Changing a field value before save
ahernandez,
I would let nuBuilder save the record first and then update the record(s) you want in After Save with nuRunQuery().
Steven
I would let nuBuilder save the record first and then update the record(s) you want in After Save with nuRunQuery().
Steven
-
- Posts: 49
- Joined: Thu May 03, 2018 12:08 pm
Re: Changing a field value before save
Good Morning Steven,
By trial and error I have reached that conclusion and now it works fine.
For the moment, in one way or another, I am managing to save all the problems that arise.
Step by step this is taking shape!
thank you very much for your help.
By trial and error I have reached that conclusion and now it works fine.
For the moment, in one way or another, I am managing to save all the problems that arise.
Step by step this is taking shape!
thank you very much for your help.
-
- Posts: 49
- Joined: Thu May 03, 2018 12:08 pm
Re: Changing a field value before save
By the way...
How to control if nuRunQuery has failed updating or inserting records?
How to control if nuRunQuery has failed updating or inserting records?
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: Changing a field value before save
You can try nuErrorFound()
Usage:
From the v3 Wiki, not documented on the v4 wiki. It might still work in v4'This function returns true if an error has occurred. This is used to ensure that if an error occurs the program is able to stop before committing erroneous data to the database.
Usage:
Code: Select all
$t = nuRunQuery($sql);
if (nuErrorFound()) {
return;
}
Re: Changing a field value before save
ahernandez,
SQL errors will show up in Debug Results.
Steven
SQL errors will show up in Debug Results.
Steven
You do not have the required permissions to view the files attached to this post.
-
- Posts: 49
- Joined: Thu May 03, 2018 12:08 pm