Accessing Child Data When No MVL or MVF Is Defined
To access child records when there is a link between parent and child buscomp, but a multi-value link and multi-value fields do not exist in the parent buscomp, the script should do the following steps:
1. Instantiate parent buscomp and query it for a valid record for which to retrieve the child data.
2. If a valid parent record is found, then instantiate the child buscomp using the same business object reference used to instantiate the parent buscomp.
3. Execute a query on the child buscomp 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 Contacts associated to an Opportunity as well as the Role of the Account on the Opportunity. Role is stored in the intersection table.
Dim oOpportunityBO as BusObject
Dim oOpportunityBC as BusComp
Dim oContactBC 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
If nMoreData Then
' Get contacts associated to Opp.
Set oContactBC = oOpportunityBO.GetBusComp("Contact")
With oContactBC
.ClearToQuery
.SetViewMode AllView
.ActivateField "First Name"
.ActivateField "Last Name"
.ActivateField "Role" ' <= Field in intersection table
.SetSearchSpec "Last Name", "*"
.ExecuteQuery ForwardOnly
nMoreData = .FirstRecord()
End With
Do While nMoreData
' Navigate through contacts for the Opp
sMessage = sMessage & " | " & _
oContactBC.GetFieldValue("First Name")
sMessage = sMessage & " " & _
oContactBC.GetFieldValue("Last Name")
sMessage = sMessage & ", Role: " & _
oContactBC.GetFieldValue("Role")
nMoreData = oContactBC.NextRecord()
Loop
sMessage = "Contacts: " & sMessage Else
sMessage = "No Records found"
End If
' Destroy objects
Set oContactBC = Nothing
Set oOpportunityBC = Nothing
Set oOpportunityBO = Nothing
Many-to-many relationships can also store data in the intersection table. During the configuration of these relationships, data in the intersection table is added to the child buscomp as joined fields. Thus this intersection data can be accessed as any other regular field using the GetFieldValue method on the child buscomp. Note that columns in the intersection table can store data that makes sense for only one side of the relationship. For instance, the column ROLE_CD in the S_OPTY_CON table stores the role of a contact in an opportunity. This column makes sense only in the context of a parent-child relationship where Opportunity is the parent record with several Contacts as child records. In this case, the ROLE_CD should be accessed through a Contact business component instantiated from an Opportunity business object.
Also note that the parent record must be also found before inserting or updating new child records.
Wednesday, June 25, 2008
Posted by Spidermen,Ice age,Age Of Empire latest at 11:16 AM
Subscribe to:
Post Comments (Atom)
1 comments:
Hey dude..please continue blogging ..this stuff is very useful for newbies like me
Post a Comment