Wednesday, June 25, 2008

Accessing Child Data in MVFs

The steps to access child records when a multi-value link and multi-value fields exist in the parent business component are as follows:

1. Instantiate the parent buscomp and query it for a valid record.
2. If a valid parent record is found, retrieve the multi-value group business component that holds the child records. To get a reference to the multi-value buscomp use the GetMVGBusComp method on the parent buscomp. The name of the multi-value field must be passed as parameter for the GetMVGBusComp method.
3. Execute a query on the MVGBusComp to retrieve all the child records.
4. Use GetFieldValue and NextRecord methods to retrieve field values or to move between records.

The following Siebel VB sample code shows how to retrieve all Sales Reps associated to an Opportunity.

Dim oOpportunityBO as BusObject
Dim oOpportunityBC as BusComp
Dim oPositionBC as BusComp
Dim sMessage as String
sMessage = ""

Set oOpportunityBO = theApplication.GetBusObject("Opportunity")
Set oOpportunityBC = oOpportunityBO.GetBusComp("Opportunity")
With oOpportunityBC
.ClearToQuery
.SetViewMode AllView
.ActivateField "Name"
.SetSearchSpec "Name", "40 Seat*"
.ExecuteQuery ForwardOnly
nMoreData = .FirstRecord()
End With

'Important: Ensure a valid parent record has been found
If nMoreData Then
'Get Sales Reps associated to Opp.
Set oPositionBC = oOpportunityBC.GetMVGBusComp("Sales Rep")
With oPositionBC
.ClearToQuery
.SetViewMode AllView
.ActivateField "First Name"
.ActivateField "Last Name"
.SetSearchSpec "Last Name", "*"
.ExecuteQuery ForwardOnly
nMoreData = .FirstRecord()
End With
Do While nMoreData
' Navigate through Sales Rep for the Opp
sMessage = sMessage & " | " & _
oPositionBC.GetFieldValue("First Name")
sMessage = sMessage & " " & _
oPositionBC.GetFieldValue("Last Name")

nMoreData = oPositionBC.NextRecord()
Loop

sMessage = "Sales Rep: " & sMessage
Else
sMessage = "No Opp records found"
End If

' Destroy objects
Set oPositionBC = Nothing
Set oOpportunityBC = Nothing
Set oOpportunityBO = Nothing

0 comments:

 
template by suckmylolly.com flower brushes by gvalkyrie.deviantart.com