Forum Discussion

JuleneDS's avatar
JuleneDS
New Contributor II
12 days ago
Solved

getLiteralParameterValue in a KPI formula

I would like to use a parameter value in a KPI in my API_Calculate business rule.

I have a literal value parameter and we will change the default value ahead of time to control which formula runs. I'm trying to pull the current default value with the following:

Dim param As String = BRApi.Dashboards.Parameters.GetLiteralParameterValue(si, False, Nothing, "myFlag")

When it gets to that line it throws a "Object reference not set to an instance of an object". 

Any ideas?

5 Replies

  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    As DanielWillis​ has mentioned, you cannot pass Nothing(null) as an argument for the Workspace Guid parameter in GetLiteralParameterValue.  Instead pass in the workspace id of the workspace where your parameter lives.

    At a minimum you need something like this:

    Dim workspaceId As Guid = BRApi.Dashboards.Workspaces.GetWorkspaceIDFromName(si, False, "Your Workspace Name")
    Dim myFlagValue As String = If(BRApi.Dashboards.Parameters.GetLiteralParameterValue(si, False, workspaceId , "myFlag"), "")

     

    • JuleneDS's avatar
      JuleneDS
      New Contributor II

      We set up all our dashboard under "Default" workspace. Using just your first line with "Default" and I'm still getting the same error. (I saw in another thread someone using Nothing or GUID.empty for the default which is why I tried that.) 

      • RobbSalzmann's avatar
        RobbSalzmann
        Valued Contributor II

        Please post your code, could be something else causing the error.

        The id of the default workspace is the same as Guid.Empty ('00000000-0000-0000-0000-000000000000') , so that would work.
        You can use:
        New Guid()
        Guid.Empty
        Nothing

        they all do the same thing in vb.  If you are still getting the null pointer error, then its something else in your code.

        Its helpful to use null coalescence in cases where unexpected nulls may cause the null pointer error, "Object not set to a reference of an object", to happen