Developing and Deploying Siebel Business Applications > Creating a Virtual Business Component > Code Samples >
Code to Copy into General:Declarations
For each of the following code samples, copy the code into the General:Declarations text entry window, then choose File > Save.
(declaration)
Dim FieldCount As Integer Dim NoOfRecords As Integer Dim DataSource As String Dim ColumnsReqd As String Dim VBCName as String
Pal_Init
Sub Pal_Init (Inputs as PropertySet, Outputs as PropertySet)
Dim theFieldName(100) As String Dim ParamText as String
' Identify setup details of calling VBC and add as Parameter to Service
ParamText = Inputs.GetProperty("Parameters") VBCName = Inputs.GetProperty("Business Component Name")
Me.SetProperty VBCName, ParamText me.SetProperty VBCName & "Qry", "None"
If ParamText <> "" Then DataSource = Left(ParamText,Instr(ParamText,";")-1) ParamText = Mid(ParamText,Instr(ParamText,";")+1) FieldCount = CVar(Left(ParamText,Instr(ParamText,";")-1)) ColumnsReqd = Mid(ParamText,Instr(ParamText,";")+1) End If
' Initialize the full list of Fields Available
Open DataSource For Input As #1 For Count = 1 To FieldCount Input #1,theKey theFieldName(Count) = RTrim(theKey) Outputs.SetProperty theFieldName(Count), "" Next Count Close #1
End Sub
Pal_Insert
Sub Pal_Insert (Inputs As PropertySet, Outputs As PropertySet)
Dim InputFields(100) As String Dim InputValues(100) As String Dim NoOfValues As Integer Dim InputPS As PropertySet Dim OutputStr As String Dim PadReqd As Integer
NoOfValues = 0
' ******************************************************************************** ' * Establish the Value Pairs to Be Used for Insert from the Inputs Property set * ' ***********************************************************************************
If Inputs.GetFirstProperty <> "" Then Set InputPS=TheApplication.NewPropertySet() Set InputPS = Inputs.GetChild(0) InputFields(1) = InputPS.GetFirstProperty InputValues(1) = InputPS.GetProperty(InputPS.GetFirstProperty) NoOfValues = NoOfValues + 1 For i = 2 to FieldCount InputFields(i) = InputPS.GetNextProperty If InputFields(i) <> "" Then InputValues(i) = InputPS.GetProperty(InputFields(i)) NoOfValues = NoOfValues + 1 End If Next i End If
' *********************************************************************** ' * Create the Output String for Writing to the File in the right order * ' *************************************************************************
Open DataSource For Input As #1
For Count = 1 To FieldCount PadReqd = 1 ' Identify by default we need a Pad string in the file Input #1,theKey For i = 1 to NoOfValues If InputFields(i) = theKey Then PadReqd = 0 If OutputStr <> "" Then OutputStr = OutputStr & "," End If OutputStr = OutputStr & InputValues(i) End If Next i If PadReqd = 1 Then If OutputStr <> "" Then OutputStr = OutputStr & "," End If OutputStr = OutputStr & " " End If Next Count
Close #1
' *************************************************** ' * Create the Output String In the DataSource File * ' *****************************************************
Open DataSource For Append As #1
Print #1,OutputStr
Close #1
End Sub
Pal_PreInsert
Sub Pal_PreInsert (Outputs As PropertySet)
' ************************************************************************************ ' * A Pre Insert Method is Required before any insert is applied, Its use is * ' * to provide Default Values, This service does not provide any defaults, But * ' * must return a populated property set, so this points to the first field by default. * ' ************************************************************************************
dim newRow As PropertySet set newRow = TheApplication.NewPropertySet() newRow.SetProperty Left(ColumnsReqd,Instr(ColumnsReqd,",")-1),"" Outputs.AddChild newRow
End Sub
Pal_Query
Sub Pal_Query (Inputs as PropertySet, Outputs as PropertySet)
' *************************************************************************** ' * The adding of properties in the me.SetProperty statements in this * ' * code is used To store key information and the relevant data against * ' * parameters identified by the VBC name. This technique is used to create * ' * a persistantstore and negate yhe need for repeat calls to the external * ' * source for the same data. * ' *****************************************************************************
Dim Row(999) As PropertySet
Dim theFieldName(100) As String Dim QueryValues(100) As String Dim QueryFields(100) As String Dim QueryList As PropertySet Dim ColList, ColData, QryData As String Dim OutColCount, OutRowCount, NoOfQs, RowMatches, DoQuery As Integer
DoQuery = 1 NoOfQs = 0 OutColCount = 0 OutRowCount = 0
' **************************************************************************** ' * Establish the list of Columns Which define the Query Values from the VBC * ' *******************************************************************************
Set QueryList = TheApplication.NewPropertySet() Set QueryList = Inputs.GetChild(0)
' Inputs.GetChild(0) retrieves user inputs ,like ("First Name","Angela") , etc...
If QueryList.GetFirstProperty <> "" Then
QueryFields(1) = QueryList.GetFirstProperty QueryValues(1) = QueryList.GetProperty(QueryList.GetFirstProperty) NoOfQs = NoOfQs + 1 QryData = QueryFields(1) & "=" & QueryValues(1) For i = 2 to FieldCount QueryFields(i) = QueryList.GetNextProperty If QueryFields(i) <> "" Then QueryValues(i) = QueryList.GetProperty(QueryFields(i)) NoOfQs = NoOfQs + 1 QryData = QryData & ";" & QueryFields(i) & "=" & QueryValues(i) End If Next i End If
' ********************************************************************************* ' * Establish If Query is same as Last Time for this VBC and If So Set Query Flag * ' * to use Persistant Cache ' ***********************************************************************************
If me.GetProperty(VBCName & "Qry") <> QryData Then me.SetProperty VBCName & "Qry", QryData Else DoQuery = 0 End If
' ********************************************************************************* ' * Establish Full List of Columns Available and Which ones are needed by the VBC * ' * Where not required, Identify this with Column Value Not Required CVNR * ' ************************************************************************************
If DoQuery = 1 Then
Open DataSource For Input As #1 For Count = 1 To FieldCount Input #1,theKey If Instr(ColumnsReqd,theKey) <> "0" Then theFieldName(Count) = RTrim(theKey) OutColCount = OutColCount + 1 Else theFieldName(Count) = "CVNR" End If Next Count
me.SetProperty VBCName & "ColCnt", CStr(OutColCount)
' ********************************************************************************* ' * Retreveal of Data from Text File, Including ignoring Columns Not Required and * ' * Ignoring rows which do not match the selection criterion * ' ************************************************************************************
For r = 1 to 999
On Error Goto EndLoop rowMatches = 1 'set to true Input #1, theKey theValue = RTrim(theKey) If theValue <> "" Then Set Row(r) = TheApplication.NewPropertySet() If theFieldName(1) <> "CVNR" Then Row(r).SetProperty theFieldName(1), theValue ColList = theFieldName(1) ColData = theValue For x = 1 to NoOfQs If QueryFields(x) = theFieldName(1) and QueryValues(x) <> theValue Then rowMatches = 0 End If Next x End If For Count = 2 To FieldCount Input #1, theKey theValue = RTrim(theKey) If theFieldName(Count) <> "CVNR" Then Row(r).SetProperty theFieldName(Count), theValue ColList = ColList & ";" & theFieldName(Count) ColData = ColData & ";" & theValue For x = 1 to NoOfQs If QueryFields(x) = theFieldName(Count) and QueryValues(x) <> theValue Then rowMatches = 0 End If Next x End If Next Count If rowMatches = 1 Then Outputs.AddChild Row(r) OutRowCount = OutRowCount + 1 me.SetProperty VBCName & CStr(OutRowCount), ColData End If Else
EndLoop:
Exit For End If Next r Close #1 me.SetProperty VBCName & "RowCnt", CStr(OutRowCount) me.SetProperty VBCName & "Col", ColList Else
' ******************************************************************************** ' * Re Create Output property set from the Persistant Cache held in the Business * ' * Service Property Set ' **********************************************************************************
OutColCount = CVar(GetProperty(VBCName & "ColCnt")) OutRowCount = CVar(GetProperty(VBCName & "RowCnt")) For i = 1 to OutRowCount ColList = GetProperty(VBCName & "Col") ColData = GetProperty(VBCName & CStr(i)) Set Row(i) = TheApplication.NewPropertySet() For x = 1 to OutColCount-1 theField = Left$(ColList,Instr(ColList,";")-1) theValue = Left$(ColData,Instr(ColData,";")-1) ColList = Mid$(ColList,Instr(ColList,";")+1) ColData = Mid$(ColData,Instr(ColData,";")+1) Row(i).SetProperty theField, theValue Next x Row(i).SetProperty ColList, ColData Outputs.AddChild Row(i) Next i End If
End Sub
|