Page 1 of 1
Add Default Value Problem (v2022)
Posted: Thu Mar 21, 2024 12:44 am
by josejad
Hi all:
I have a table where every user insert its own data, so the id field is hidden and the default value is set to CurrentUserId(). So far so good.
Now, I need another kind of users who can add its own data but other people data too, so this user can see the id field, and it shows a multiple select with other people id's.
In the row_inserting function, I explode the id field, and if it has more than a value, I do a foreach insert in the database.
The problem I've facing is if I just add one record for just one user, different than the one is logged, the id field is set to CurrentUserId(). I realize this so I deleted the default value for the field. But I still get the CurrentUserId() in my db.
Probably the problem is returning TRUE, but the $rsnew['user_id'] should be the form value, but it's CurrentUserId().
public function rowInserting($rsold, &$rsnew) {
$ArrayIds = explode(',', $rsnew['user_id']); //Comprobamos ahora si se está agregando más de un opoerario por un Jefe de Equipo
if (count($ArrayIds)>1){ //Inserting more than one user
foreach ($ArrayIds as $user){ // Loop through all the records
ExecuteStatement("INSERT INTO `mytable`(`user_id`, `date`,) VALUES ('" . $user . "','" . $rsnew['date']");
}
$this->setSuccessMessage($user_id. " added succesfuly");
} //foreach
} else { //adding just one user (MAYBE DIFFERENT FROM THE USER LOGGED IN)
}
return TRUE;
}
Thanks
Re: Add Default Value Problem (v2022)
Posted: Thu Mar 21, 2024 9:46 am
by arbei
josejad wrote:
ExecuteStatement("INSERT INTO `mytable`(`user_id`, `date`,) VALUES ('" . $user . "','" . $rsnew['date']");
You have syntax error in your SQL.
Re: Add Default Value Problem (v2022)
Posted: Thu Mar 21, 2024 9:47 am
by mobhar
Did you mean you setup Auto-Update Value to CurrentUserID()
from Fields setup?
If so, then it will save the current user id whenever a record is updated.
Or, did you setup the Lookup Table for the user_id field with Multiple option enabled from the Edit Tag pane?
Re: Add Default Value Problem (v2022)
Posted: Thu Mar 21, 2024 2:38 pm
by josejad
arbei wrote:
You have syntax error in your SQL.
Just in the post, it's not the real SQL, I've simplified it for posting and it can be wrong
Re: Add Default Value Problem (v2022)
Posted: Thu Mar 21, 2024 2:42 pm
by josejad
mobhar wrote:
Did you mean you setup Auto-Update Value to CurrentUserID()
from
Fields setup?
If so, then it will save the current user id whenever a record is updated.
It was setup originally, but now it's not set. I thought this was the error and it will be fixed when I delete the Auto-update value.
Or, did you setup the Lookup Table for the user_id field with
Multiple option enabled from the Edit Tag pane?
Yes, now it's set this way, Lookup Table for the user_id with multiple option enabled in the Edit Tag panel
Re: Add Default Value Problem (v2022)
Posted: Thu Mar 21, 2024 4:35 pm
by mobhar
Please post the following information for more discussion:
- Table schema (
CREATE TABLE ...
) including some records example (INSERT INTO ...
),
- Your Lookup Table setup for the field, including the Link field and Display field setup,
- Your latest actual code in Row_Inserting server event.
Re: Add Default Value Problem (v2022)
Posted: Mon Mar 25, 2024 4:42 am
by josejad
Hi friends:
As always, thanks for your help... and... like always too... simplifying my code to post it... the error stops happening, so, it was my fault. Not sure where I set the default value, but now it's solved.
Thanks