Forum Discussion

jordielane's avatar
jordielane
New Contributor III
2 years ago

Dynamic Calc - return lesser value

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 
  • 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

  • MikeG's avatar
    MikeG
    Contributor III

    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

      • MikeG's avatar
        MikeG
        Contributor III

        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 !

  • MikeG's avatar
    MikeG
    Contributor III

    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.

    • jordielane's avatar
      jordielane
      New Contributor III

      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. 

  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    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)