Planning Analytics

Planning Analytics

Get AI-infused integrated business planning

 View Only
  • 1.  PAFE API: ExecuteFunction

    Posted Tue December 19, 2023 01:51 PM
    Edited by Adam Havas Tue December 19, 2023 01:51 PM

    Hello Community,

    Within PAFE API for ExecuteFunction, is there a capability to handle optional parameters?

    For example, if my TI script has:

    p1 (required)
    p2 (required)
    p3 (optional)

    I'd like to simply do:

    ExecuteFunction(host_name, server_name, process_name, "val1,val2") -> and not have to specify a blank for p3.

    Seeing the REST API calls going back and forth, I get the complexity of my request ... so even this form would work:

    ExecuteFunction(host_name, server_name, process_name, "p1:val1,p2:val2") -> This solves for any ambiguities

    This is critical if the TI changes on the server side to add additional capabilities in the form of additional optional parameters.



    ------------------------------
    Adam
    ------------------------------



  • 2.  RE: PAFE API: ExecuteFunction

    Posted Wed December 20, 2023 11:24 AM
    Edited by Adam Havas Wed December 20, 2023 11:25 AM

    Since it's Christmastime and I'm feeling extra kind, I decided to do a work-around and share with our community.

    You can import into any book that works with standard PAFE API 

    Test_Run_Process() is a sample of how to use:

    Option Explicit
    
    Const Host_Name As String = "https://xxxxxxx.planning-analytics.ibmcloud.com"
    Const Server_Name As String = "yyyyyyy"
    
    Sub Run_Process(Process_Name As String, Parameter_Name_Value As Scripting.Dictionary)
    
        ' Background:
        ' - PAFE API ExecuteFunction takes a comma-separated string of TI parameter values (but not the name).
        ' - The TI parameter values have to be in the correct order.
        ' - You cannot skip optional TI parameters.
        ' Goal:
        ' - In this helper subroutine, take a dictionary which can have TI parameter names and values in any order.
        ' - Optional TI parameters can be excluded from the dictionary.
        ' - TI process executes correctly with PAFE API ExecuteFunction.
        ' How:
        ' - Using REST API call, get the correct order of TI parameters, and populate the Parameter_Value_String in that order
        ' - Populate a blank for optional TI parameters
        
        Dim Parameter_List() As String: Parameter_List() = Get_Parameter_List(Process_Name)
        Dim Current_Parameter_Name As Variant
        Dim Parameter_Value_String As String: Parameter_Value_String = ""
        Dim Run_Once As Boolean: Run_Once = False
        
        For Each Current_Parameter_Name In Parameter_List()
            
            If Run_Once = True Then
                Parameter_Value_String = Parameter_Value_String & ","
            End If
            
            If Parameter_Name_Value(Current_Parameter_Name) <> "" Then
                Parameter_Value_String = Parameter_Value_String & Parameter_Name_Value(Current_Parameter_Name)
            End If
            
            Run_Once = True
        
        Next
    
        CognosOfficeAutomationObject.ExecuteFunction _
            Host_Name, _
            Server_Name, _
            Process_Name, _
            Parameter_Value_String
    
    End Sub
    
    Function Get_Parameter_List(Process_Name As String) As String()
    
        If Process_Name = "" Then Exit Function
        If Reporting.ActiveConnection Is Nothing Then Exit Function
    
        Dim REST_API_Header As String: REST_API_Header = "/tm1/" & Server_Name & "/api/v1/Processes('" & Process_Name & "')"
        Dim REST_API_Response As Object: Set REST_API_Response = Reporting.ActiveConnection.Get(REST_API_Header)
        If REST_API_Response Is Nothing Then Exit Function
        
        Dim Current_Parameter_ID As Long
        Dim Parameter_Count As Long: Parameter_Count = REST_API_Response.Properties.item("Parameters").Members.Count - 1
        Dim Parameter_List() As String: ReDim Parameter_List(Parameter_Count)
        
        For Current_Parameter_ID = 0 To Parameter_Count
            Parameter_List(Current_Parameter_ID) = REST_API_Response.Properties.item("Parameters").Members.item(Current_Parameter_ID).Properties.item("Name").Value
        Next Current_Parameter_ID
        
        Get_Parameter_List = Parameter_List()
    
    End Function
    
    Sub Test_Run_Process()
    
        Dim Parameter_Name_Value As Scripting.Dictionary: Set Parameter_Name_Value = New Scripting.Dictionary
        
        Parameter_Name_Value.Add "pPar3", "C3"
        Parameter_Name_Value.Add "pPar2", "B2"
        Parameter_Name_Value.Add "pPar1", "A1"
    	' Parameter_Name_Value.Add "pPar7", "G7" ' Optional parameters are not necessary to include
        Parameter_Name_Value.Add "pPar6", "F6"
        Parameter_Name_Value.Add "pPar4", "D4"
        Parameter_Name_Value.Add "pPar5", "E5"
        
        Run_Process "My Process", Parameter_Name_Value
    
    End Sub



    ------------------------------
    Adam
    ------------------------------