cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Computed Value in Trigger

nborrerojr.
7-Bedrock

Computed Value in Trigger

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.

1 ACCEPTED SOLUTION

Accepted Solutions
LLawton
14-Alexandrite
(To:nborrerojr.)

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.

View solution in original post

5 REPLIES 5
KaelLizak
14-Alexandrite
(To:nborrerojr.)

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


Kind Regards,
Kael Lizak

Senior Technical Support Engineer
PTC Integrity Lifecycle Manager

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().

LLawton
14-Alexandrite
(To:nborrerojr.)

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.

KaelLizak
14-Alexandrite
(To:nborrerojr.)

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


Kind Regards,
Kael Lizak

Senior Technical Support Engineer
PTC Integrity Lifecycle Manager
Top Tags