Forum Discussion

Bella_Yu's avatar
Bella_Yu
New Contributor II
5 months ago

Call Data Adapter with GetAdoDataSetForAdapter and Pass Parameter Value

The goal is to get underlying dashboard data, I'm developing business rule using VB to call respective data adapter. The issue is, the data adapter has 1 parameter, not sure if it's possible to pass parameter value to it in BR.

Below is my BR code and sample sql scripts for the data adapter,

Dim isSystemLevel As Boolean = False
Dim workspaceID As Guid = BRApi.Dashboards.Workspaces.GetWorkspaceIDFromName(si, isSystemLevel, "Default")
Dim adapterName As String = "da01_entity_hierarchy_filtered"
Dim rsTableName As String = "OutputTable"
Dim dctVars As New Dictionary(Of String, String)
			
Using ds As DataSet = brapi.Dashboards.Process.GetAdoDataSetForAdapter(si, isSystemLevel, workspaceID, adapterName, rsTableName, dctVars)	
	If ds.Tables.Count > 0 Then 'If there are >0 tables in the results
		Using dt As DataTable = ds.Tables(0).Copy()
			op_table = dt.Copy() ' Clone the DataTable
					
		End Using
	End If	
End Using
 
 
SELECT C.NAME
FROM Member C 
WHERE C.Name = '|!Select_Entity_EP!|' 

 

 

 

  • DanielWillis's avatar
    DanielWillis
    Valued Contributor

    Hi Bella

    I think the better approach is to rework this a little bit so that instead of your business rule retrieving data from your data adapter, you have your data adapter retrieving data from your business rule. For me this is much more flexible and would make your new requirement quite easy to implement with all the logic there in the BRs. The rework would most likely be quite trivial.

    Your new data adapter would look something like this:

    Regards,

    Daniel

  • sameburn's avatar
    sameburn
    Contributor II

    Hi Bella_Yu 

    First you need to pass the parameter selected value into your logic.  Then you need to pass that value into the dctVars dictionary that you had created (which was empty in your example).  The BRApi expects you to pass in a dictionary with parameters to resolve here.  I have provided sample code below for using a dashboard dataset rule to pick up value from your original data adapter

    						' {YourBusinessRuleName}{YourFunctionName}{Entity=[|!Select_Entity_EP!|]}
    						If args.DataSetName.XFEqualsIgnoreCase("YourFunctionName") Then
    							
    							' Retrieve Entity passed in from Parameter Value using args.NameValuePairs
    							Dim entityName As String = args.NameValuePairs.XFGetValue("Entity")
    							
    							Dim isSystemLevel As Boolean = False
    							Dim workspaceID As Guid = BRApi.Dashboards.Workspaces.GetWorkspaceIDFromName(si, isSystemLevel, "Default")
    							Dim adapterName As String = "da01_entity_hierarchy_filtered"
    							Dim rsTableName As String = "OutputTable"
    							Dim dctVars As New Dictionary(Of String, String)
    							
    							'  Add Parameter values you want to resolve to the dictionary created (that we pass into the BRApi)
    							' In this case the Key will be the name of the Parameter you want to resolve and the Value will be the value from your parameter selection
    							dctVars.Add("Select_Entity_EP", entityName)	
    							
    							Using ds As DataSet = brapi.Dashboards.Process.GetAdoDataSetForAdapter(si, isSystemLevel, workspaceID, adapterName, rsTableName, dctVars)	
    								If ds.Tables.Count > 0 Then 'If there are >0 tables in the results
    									Using dt As DataTable = ds.Tables(0).Copy()
    										op_table = dt.Copy() ' Clone the DataTable
    												
    									End Using
    								End If	
    							End Using						
    						
    						End If

    You could then call the function using something like this (depending on your calling method) e.g. 

    {YourBusinessRuleName}{YourFunctionName}{Entity=[|!Select_Entity_EP!|]}

    But regardless of which type of rule you pick to execute your logic. The principles will be the same e.g pass your parameter(s) into your logic and then resolve them using the dictionary, in your case dctVars