Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
How do you get a field value in a trigger if that field is computed? If I use getFieldDisplayString then nothing is returned. If I use getFieldValue then I get a null.
Solved! Go to Solution.
Is your trigger in PRE mode?
It's been a couple months since I had to look into that but I'm pretty sure that in that case, your formula may be right but the computation isn't performed by Integrity yet. The only way you get the new calculated value it in POST mode. Of course, that's not helpful if you want to do something with it and save it somewhere. By the way, getFieldValue and get NewFieldValue don't make a difference here. They both display the old value, which in your case is probably not yet set and therefore null.
I've looked into all kinds of ways to cause another field to change and therefore trigger a caclulation after the fact, use the API in post mode, etc, but I usually end up with a secondary edit and something that's going to be incredibly difficult to maintain, or confuses the user (they get an edit conflict when there is no apparent reason).
If possible, it's better to do (or redo) whatever calculation the field does in your trigger and use the computed field for display only.
I agree with Joe, getting the calculation done when you call the field would be of great help, although I can see why it's probably technically challenging.
Hello Nolin,
Are you sure the value of the field isn't actually null? If you are, then please open a case for this.
Regards,
Kael
I agree with Kael's response. Using the getFieldValue() call should cause the field to be computed and get your result. If the computation itself is returning a null, you should revisit the computed expression and maybe wrap it in a check for isEmpty().
Is your trigger in PRE mode?
It's been a couple months since I had to look into that but I'm pretty sure that in that case, your formula may be right but the computation isn't performed by Integrity yet. The only way you get the new calculated value it in POST mode. Of course, that's not helpful if you want to do something with it and save it somewhere. By the way, getFieldValue and get NewFieldValue don't make a difference here. They both display the old value, which in your case is probably not yet set and therefore null.
I've looked into all kinds of ways to cause another field to change and therefore trigger a caclulation after the fact, use the API in post mode, etc, but I usually end up with a secondary edit and something that's going to be incredibly difficult to maintain, or confuses the user (they get an edit conflict when there is no apparent reason).
If possible, it's better to do (or redo) whatever calculation the field does in your trigger and use the computed field for display only.
I agree with Joe, getting the calculation done when you call the field would be of great help, although I can see why it's probably technically challenging.
My trigger is a Pre trigger. What you're saying makes sense and I actually needed to calculate it more manually eventually anyway so I will take that route and just recalculate the value in the trigger itself. Thank you for the help.
Hello Nolin,
Laurent's point is right on. If his post got you to your resolution, could you mark it as Correct Answer, please, so that other people who find this while searching can get pointed in the right direction quickly?
Thanks,
Kael