Calculated Fields or Hooks?

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
rpierce
Veteran Member
Posts: 255
Joined: 2018-11-26 13:55
Location: Washington State

Calculated Fields or Hooks?

Post by rpierce » 2022-11-21 22:08

Hi,

I have a table with a field named "rank". I need this field set to 1, 2, 3, or 4 based on a selection made by a user in another field in the same table called "Risk". The "Risk" field is set as Radio buttons with the options, Low Risk, Medium Risk, High Risk and Stop Work. I've experimented with Calculated field for the field and have not gotten it yet.

Can anyone help?

Ray

rpierce
Veteran Member
Posts: 255
Joined: 2018-11-26 13:55
Location: Washington State

Re: Calculated Fields or Hooks?

Post by rpierce » 2022-11-21 23:02

Ok, so I tried using the before_insert hook with if statements:

if($data['risk'] = "Low Risk"){$data['rank'] = 1;} and that worker fine if I only selected the "Low Risk" radio option. If I select any other radio option the selection changed to "Low Risk" when I save the record.

Then I added an additional if statement: if($data['risk'] = "Medium Risk"){$data['rank'] = 2;}. As long as I select radio option "Medium Risk" it works. If I select any other option it gets changed to "Medium Risk" when saved. The same issues exist if I use an elseif statement after the if statement.

rpierce
Veteran Member
Posts: 255
Joined: 2018-11-26 13:55
Location: Washington State

Re: Calculated Fields or Hooks?

Post by rpierce » 2022-11-21 23:12

Well, it seems to be working now. I found that using == rather than = for the condition statement made all the difference.

if($data['risk'] == "Low Risk"){$data['rank'] = 1;}

It helps just to ask this forum!! Even if I figure it out on my own.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Calculated Fields or Hooks?

Post by jsetzer » 2022-11-22 10:41

In most programming languages '=' is a right-to-left assignment whereas '==' is a left against right comparison, returning boolean.

$a = 1;
$a = $a == 2;
// $a is false now 😉
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

rpierce
Veteran Member
Posts: 255
Joined: 2018-11-26 13:55
Location: Washington State

Re: Calculated Fields or Hooks?

Post by rpierce » 2022-12-01 17:28

Thank you for that Jan!! I love getting helpful tidbits from you all.

Post Reply