Skip to main content
Newcomer
June 21, 2023
Solved

Dynamic Calc - return lesser value

  • June 21, 2023
  • 3 replies
  • 0 views

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.

If api.Data.GetDataCell("A#RPT_Cash") > "500000" Then
  Return "500000"
Else If api.Data.GetDataCell("A#RPT_Cash") < "500000" Then
  Return api.Data.GetDataCell("A#RPT_Cash")
End If 
Best answer by MikeG

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

3 replies

MikeG
Contributor
June 21, 2023

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.

Newcomer
June 21, 2023

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. 

MikeG
MikeGAnswer
Contributor
June 21, 2023

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

Newcomer
June 22, 2023

This worked, thank you!

MikeG
Contributor
June 22, 2023

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 !

RobbSalzmann
Legend
June 26, 2023

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)