Example of Accessing Data from a New Business Component Instance

The example in this topic describes how to create a new business object instance and a business component instance. It uses the PreSetFieldValue event of the Opportunity business component. If the user updates the Sales Stage to 07 - Verbal Agreement, then Siebel CRM requires the user to associate a decision maker with the opportunity. Otherwise, Siebel CRM resets it to the previous value. To determine if a vice president or president is associated with the opportunity, Siebel CRM searches the contacts that it associates with the opportunity.

The following steps describe the logical flow of object interface methods that Siebel CRM uses to create a new business component instance:

  1. GetBusComp.

  2. SetViewMode. This method is optional. You can use it to modify the default value of the view mode.

  3. ActivateField.

  4. ClearToQuery.

  5. SetSearchSpec or SetSearchExpr.

    It is not necessary to activate a field that includes a search specification and a search expression, unless the GetFieldValue method or the SetFieldValue method also references this field.

  6. ExecuteQuery.

Example of Using Siebel VB to Access Data from a New Business Component Instance

The following example uses Siebel VB to access data from a new business component instance:

Function BusComp_PreSetFieldValue (FieldName As String, FieldValue As String) As 
Integer

Dim RetValue As Integer
RetValue = ContinueOperation
Select Case FieldName
   Case "Sales Stage"
      If FieldValue = "08 - Negotiation" Then
         ' Do not allow the sales cycle to be changed to this value
         ' if the decision-maker is not a contact for the Oppty.
         ' Decision-maker defined as anyone with rank VP and above
         Dim oBusObj As BusObject
         Dim sRowId As String
         Dim iViewMode As Integer
         sRowId = GetFieldValue("Id")
         iViewMode = GetViewMode
         Set oBusObj = TheApplication.ActiveBusObject
         ' Parent-child relationship is established if
         ' BusComps are instantiated from the same BusObject.
         ' The ContactBC has all contact records for the
         ' current Oppty record.
         Set ContactBC = oBusObj.GetBusComp("Contact")
         With ContactBC
            .ClearToQuery
            .SetSearchSpec "Job Title", "*VP*"
            .ExecuteQuery ForwardBackward
            If (.FirstRecord = 1) Then
               TheApplication.RaiseErrorText "Found a decision maker"
            Else
               RetVal = ContinueOperation
            End If
         End With
         Set ContactBC = Nothing
         Set oBusObj = Nothing
      End If
End Select
BusComp_PreSetFieldValue = RetValue
End Function

Example of Using Siebel eScript to Access Data from a New Business Component Instance

The following example uses Siebel eScript to access data from a new business component instance:

function BusComp_PreSetFieldValue (FieldName, FieldValue)
{
   var RetValue = ContinueOperation;
   switch (FieldName)
   {
      case "Sales Stage":
      if (FieldValue == "08 - Negotiation")
      {
      //Do not allow the sales cycle to be changed to this value
      //if the decision-maker is not a contact for the Oppty.
      //Decision-maker defined as anyone with rank VP and above
         var oBusObj;
         var sRowId;
         var iViewMode;
         sRowId = this.GetFieldValue("Id");
         iViewMode = this.GetViewMode();
         oBusObj = TheApplication().ActiveBusObject();
         //Parent-child relationship is established if
         //BusComps are instantiated from the same BusObject.
         //The ContactBC has all contact records for the
         //current Oppty record.
         ContactBC = oBusObj.GetBusComp("Contact");
         with (ContactBC)
         {
            ClearToQuery();
            SetSearchSpec("Job Title", "*VP*");
            ExecuteQuery(ForwardBackward);
            if (FirstRecord())
            {
               TheApplication().RaiseErrorText("Found a decision maker");
            }
            else
            {
               RetVal = ContinueOperation;
            }
         }
         ContactBC = null;
         oBusObj = null;
      }
      break;
   }
return(RetVal);
}