06-21-2023 12:32 PM
I'm trying to do a dynamic calc to determine lesser value of an account or 500,000. I have very little experience with vb.net so this was as far as I got but it doesn't work.
Solved! Go to Solution.
06-21-2023 01:25 PM
Try this - then check your ErrorLog and confirm you are getting an Amount, you may need to provide additional POV to get the correct value for A#RPT_Cash.
Dim value As Decimal = api.Data.GetDataCell("A#RPT_Cash").CellAmount
Dim threshold As Decimal = 500000
Brapi.ErrorLog.LogMessage(si, "in Dynamic Calc, Entity= " & api.Pov.Entity.Name & ", value= " & value & ", threshold= " & threshold)
If value > threshold Then
Return threshold
Else
Return value
End If
06-21-2023 12:40 PM
Try this:
Dim value as decimal = api.Data.GetDataCell("A#RPT_Cash").CellAmount
BRapi.ErrorLog.LogMessage(si, "in Dynamic calc - Entity= " & api.pov.entity.Name & ", value= " & value)
If value < 500000 Then
You may need to provide additional POV. You need the .CellAmount after the api.Data.GetDataCell and when comparing a value no quotes are required. Quotes are needed for a String comparison.
Hope this helps.
06-21-2023 01:19 PM
Thank you for the tips. I'm not sure if its relevant but this calculation is being stored as an account member. I need it to return the lesser of the A#Rpt_Cash value or 500,000. What should the return values be after the if statement? I tried modifying what I had originally based on your reply but it still didn't work.
06-21-2023 01:25 PM
Try this - then check your ErrorLog and confirm you are getting an Amount, you may need to provide additional POV to get the correct value for A#RPT_Cash.
Dim value As Decimal = api.Data.GetDataCell("A#RPT_Cash").CellAmount
Dim threshold As Decimal = 500000
Brapi.ErrorLog.LogMessage(si, "in Dynamic Calc, Entity= " & api.Pov.Entity.Name & ", value= " & value & ", threshold= " & threshold)
If value > threshold Then
Return threshold
Else
Return value
End If
06-22-2023 12:26 PM
This worked, thank you!
06-22-2023 01:02 PM
Please comment out or delete the LogMessage write, you don't want that running after you've completed your testing. Glad that work for you @jordielane !
06-26-2023 10:36 AM - edited 03-22-2024 05:35 PM
For maintenance and readability, consider this could be a one or two line solution using the System Math API:
Dim compareVal as Decimal = api.Data.GetDataCell("A#RPT_Cash").CellAmount
Return System.Math.Min(compareVal, 500000)