I have a simple logic hook that changes the commission amount based on the user selected in the field selling_agent_c:
class sellingcommission {
function sellingcommissionfield($bean, $event, $arguments) {
if ($bean->selling_agent_c == "Will") {
$bean->selling_agent_comm_c = 10;
} else if ($bean->selling_agent_c == "Robert") {
$bean->selling_agent_comm_c = 20;
}
}
}
The hook fires, however it uses the previous user that was in the relation field “selling_agent_one.”
For example if the previous user selected was Rob and I change it to Will and click save, then the value will be 20 instead of 10.
If I save the record again, then the right value appears. It works fine when a record is created for the first time. The issue happens when I edit the record again.
It seems that the new selected user has not been updated in the DB, when the logic hook runs. The previous value is there instead and is used.
I’ve tried using an after_save and before_save, but still getting the same results.
Any ideas? Any help would be much appreciated.