Date Arithmetic in eScript
Last Modified:               16 September 2003
Area(s):                     Siebel VB/eScript/Browser Script/COM
Release(s):                  V6 (Siebel 2000-Enterprise), V7 (Enterprise), V6 (Siebel
                             2000-MidMarket), V7 (MidMarket)
Database(s):                 DB2, Microsoft, Oracle
App Server OS(s):            Windows 2000
Latest release tested
                             V7 (Enterprise)
against:
Keywords:                    date arithmetic eScript
Background
There are instances in which date arithmetic is required to implement certain business
rules. Siebel eScript provides date functions that allow users to build custom functions to
know the difference between two dates, add/subtract a number of days to a date, etc.
This document presents a set of functions that can be used in scripts to implement more
complex business rules.
Sample code provided in this document is provided only as a guideline, and not as a
final product to be used in a production environment. None of the functions
perform any validation (example: daylight savings adjustment) of the input
parameters or error trapping. The code is provided as a start point from which
actual scripts can be built, and is intended to show how some of the functions
provided by eScript can be used to perform more complex tasks.
Date arithmetic functions in eScript
function AddToDate(sourceDate, nDays, nHours, nMinutes, nSeconds,
nsign)
{
// Parameters :
// sourceDate : Date object
// nDays, nHours , nMinutes , nSeconds : Integer numbers
// nsign : Can have two values : 1 or -1
// 1 indicates to ADD to the sourceDate
// -1 indicates to SUBTRACT from the sourceDate
// Returns : A date object, after adding/subtracting ndays,hNours,nMinutes
// and nseconds to the sourceDate.
var retDate = sourceDate;
retDate.setDate(retDate.getDate()+nsign*nDays);
retDate.setHours(retDate.getHours()+nsign*nHours);
retDate.setMinutes(retDate.getMinutes()+nsign*nMinutes);
retDate.setSeconds(retDate.getSeconds()+nsign*nSeconds);
return (retDate)
}
function DiffDays(date1, date2)
{
// Parameters :
// date1 : Date object
// date2 : Date object
// Returns : Number of days between date1 and date2
return (date2.getTime()-date1.getTime())/(1000*60*60*24));
}
function DateToString(dDate)
{
// Parameters :
// dDate : Date object
// Returns : A string with the format "mm/dd/yyyy" or "mm/dd/yyyy hh:mm:ss"
var sMonth = ToString(dDate.getMonth() + 1);
if (sMonth.length == 1) {sMonth = "0" + sMonth;}
var sDay = ToString(dDate.getDate());
if (sDay.length == 1) {sDay = "0" + sDay;}
var sHours = ToString(dDate.getHours());
if (sHours.length == 1) {sHours = "0" + sHours;}
var sMinutes = ToString(dDate.getMinutes());
if (sMinutes.length == 1) {sMinutes = "0" + sMinutes;}
var sSeconds = ToString(dDate.getSeconds());
if (sSeconds.length == 1) {sSeconds = "0" + sSeconds;}
if (sHours == "00" && sMinutes == "00" && sSeconds == "00"
    return (sMonth +"/"+ sDay +"/" + dDate.getFullYear())
else
    return (sMonth +"/"+ sDay +"/" + dDate.getFullYear() +" "
    +sHours+":"+sMinutes+":"+sSeconds);
}
function StringToDate(sDate)
{
// Parameters :
// sDate : A string with the format "mm/dd/yyyy" or "mm/dd/yyyy hh:mm:ss"
// Returns : a Date object var ArDateTime = sDate.split (" ");
var ArDate = ArDateTime[0];
var splitDate = ArDate.split ("/");
var nDay = ToNumber(splitDate[1]);
var nMonth = ToNumber(splitDate[0]);
var nYear = ToNumber(splitDate[2]);
if (ArDateTime.length == 1)
    return (new Date(nYear, nMonth-1 , nDay))
else
{
    var ArTime = ArDateTime[1];
    var splitTime = ArTime.split(":");
    if (splitTime[0]=="00" && splitTime[1]=="00" && splitTime[2]=="00"
        return (new Date(nYear, nMonth-1 , nDay))
    else
    {
    var nHours = ToNumber(splitTime[0]);
    var nMinutes = ToNumber(splitTime[1]);
    var nSeconds = ToNumber(splitTime[2]);
    return (new Date(nYear,nMonth-1,nDay, nHours, nMinutes, nSeconds))
    }
}
}
Sample script
The following sample script retrieves the Service Requests that have been opened in the
last 45 days. The code is provided only as an illustration on how the functions can be
used.
var today = new Date;
var FortyFiveDaysAgo = AddToDate(today,45,0,0,0,-1);
var bo = TheApplication().GetBusObject("Service Request");
var bc = bo.GetBusComp("Service Request"); bc.ClearToQuery();
bc.SetViewMode(AllView);
bc.SetSearchSpec ("Created", ">= " + "'" + DateToString(FortyFiveDaysAgo)
+ "'");
bc.ExecuteQuery();
var moreRecs = bc.FirstRecord();
var fp = Clib.fopen("c:\\file.txt","wt");
while(moreRecs)
{
   var sCreated = bc.GetFieldValue("Created");
   var sDesc = bc.GetFieldValue("Description");
  Clib.fputs(sCreated + sDesc + "\n",fp);
  moreRecs = bc.NextRecord();
}
Clib.fclose(fp);
FAQ 1554: How to set a multi value group record as primary though
VB/eScript?
Last Modified:               25 November 2003
Area(s):                     Siebel VB/eScript/Browser Script/COM
Release(s):                  V5 (Siebel 99-Enterprise), V6 (Siebel 2000-Enterprise), V7
                             (Enterprise), V5 (Siebel 99 -MidMarket), V6 (Siebel 2000-
                             MidMarket), V7 (MidMarket)
Database(s):                 All Supported Databases
App Server OS(s):            All Supported Platforms
Latest release tested
                             V6 (Siebel 2000-Enterprise)
against:
Keywords:                    VB, eScript, set primary, child, multi-value group, MVG
Setting the primary record for a multi-value group (MVG) is part of the base
functionality in Siebel Applications. This can be configured to be set automatically
through the Auto Primary property for a multi-value link, or be directly selected by the
user in the multi-value field.
Sometimes this manipulation must be performed using Siebel eScript or Visual Basic
(VB) code in order to complete an Enterprise Integration Manager (EIM) task. An
example of when this might be needed is when an interface table does not take primaries
into account. An Assignment process may also need to set the primary record via eScript
or VB when the Workflow is not available.
In the table for the Parent Business Component there exists a column with a name like
'PR_*'. This column holds the foreign key which points to the Row Id of the child record
defined as the primary. Siebel Systems does not support directly setting the "Primary
Address Id" Field in the parent Business Component.
The "SSA Primary Field" is used for the primary child implementation. This special field
belongs to the System category and is not visible within Tools. To allow setting it
through VB or eScript, it must first be defined in the multi-value group applet.
In VB or eScript code, it is possible to take advantage of the user interface (UI) context
to mimic the end-user manipulation, using the "SSA Primary Field". From the parent
record, get the MVG business component. On this business component, execute a query
in order to retrieve the child for which the "SSA Primary Field" should be set through a
simple BusComp.SetFieldValue("SSA Primary Field", "Y"). Remember to activate
this field before launching the query.
This approach requires that specialized functionality be available. It is not available
through a COM Data Server configuration.
To summarize, the following pseudo-code provides a sample of setting a child record as
primary.
   1.   Get the MVG business component (BusComp.GetMVGBusiness Component).
   2.   Set the search criteria (BusComp.SetSearchSpec).
   3.   Activate the "SSA Primary Field" (BusComp.ActivateField).
   4.   Perform a query on this business component (BusComp.ExecuteQuery).
   5.   Go to the right record (BusComp.FirstRecord, BusComp.NextRecord).
   6.   Set "SSA Primary Field" to "Y" (BusComp.SetFieldValue).
   7.   Commit the change on the parent business component (BusComp.WriteRecord).
Note that the commit must be invoked on the parent business component and not on the
MVG business component because the foreign key belongs to the parent record.
Complete information and examples are available in the Siebel Bookshelf:
       Siebel Tools Guide, Business Objects Layer, Multi-Value Links, Primary ID
        Field
       Siebel Object Interfaces Reference, Interfaces Reference, Business Component
FAQ 1977: How to send custom HTTP headers while sending HTTP
request to external Web application through EAI HTTP Transport
business service.
Last Modified:               29 August 2003
Area(s):                     Siebel EAI
Release(s):                  V7 (Enterprise), V7 (MidMarket)
Database(s):                 DB2, Microsoft, Oracle
App Server OS(s):            AIX, Solaris, Windows NT, Windows 2000, HP-UX
Latest release tested
                             V7 (Enterprise)
against:
Keywords:                    EAI HTTP Transport, HTTP, Send, Header, Custom Header
In Siebel version 7.x, EAI HTTP Transport business service allows set-up of custom
HTTP headers while sending outbound requests. These headers might be required to send
additional information to the external Web application.
In order to generate custom headers, users need to set the input properties of the form
HDR.xxx where xxx is the header name. For example, in order to set a custom header
named "Test", input property name should be HDR.Test.
Note: Users cannot set such input property in the workflow process step because a .
(Dot) in the input argument indicates a hierarchy type. Users must write a custom
business service as a wrapper written in Siebel VB or Siebel eScript to set custom
headers and initiate the HTTP request. Users can then call this business service from the
workflow process.
Here is a sample custom business service written in eScript, which sets a custom HTTP
header named "Test" and sets its value to "MyTest".
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if (MethodName=="SendRequest")
{
var bs = TheApplication().GetService("EAI HTTP Transport");
var inp = TheApplication().NewPropertySet();
var out = TheApplication().NewPropertySet();
inp.SetProperty("HTTPRequestMethod","POST");
inp.SetProperty("HTTPRequestURLTemplate","http://localhost/test/test1.asp");
inp.SetProperty("HDR.Test","MyTest");
inp.SetValue("Hello World");
bs.InvokeMethod("Send",inp,out);
return(CancelOperation);
}
else
return (ContinueOperation);
FAQ 2067: How can Assignment Manager be invoked from SmartScripts?
Last Modified:                22 January 2004
Area(s):                      Call Center/Smartscript/CTI
Release(s):                   V7 (Enterprise), V7 (MidMarket)
Database(s):                  Oracle
App Server OS(s):             Windows 2000
Latest release tested
                              V7 (Enterprise)
against:
Keywords:                     SmartScript, Assignment Manager
Assignment Manager running in Interactive mode can be invoked from SmartScripts
using Siebel eScript or VB scripting.
With Interactive Assignment, a user (Service Representative) who is executing
SmartScripts will have to assign a record to an employee by pick assignee from a pick
list.
If the Assignment Manager is running in Dynamic mode, Dynamic Assignment manager
can be invoked automatically based on certain events. Users do not need to call it from
SmartScripts.
For example:
    1. Users can run SmartScripts to create records (for example, service requests).
    2. After the record has been created, Dynamic Assignment will automatically run
       Assignment Manager.
Scripting example (invoking assignment manager on a newly created service
request record):
    1. Create assignment rules for Service Request object (for more details about
       Assignment rules configuration, refer to Assignment Manager Administration
       guide).
2. Create new SmartScript script with following:
       1. Question1
          Name:                   SRDescription
          Answer Type:            String
          Answer Control:         Default
          Save Business
                                  Service Request
          Object:
          Save Bus Comp:          Service Request
          Save Field:             Description
          Translations:           English-American
       2. Question2
          Name:                   TestQuestion2
          Answer Type:            RDsr2
          Answer Control:         RDsr2
          Translations:           English-American
       3. Page
          Name:                   TestPage1
          First Question:         SRDescription
          Translation:            English-American
          Label:                  TestPage1
          Next Question:          TestQuestion2
       4. SmartScript
          Name:                   SmartScript_AssignSR
          Type:                   pick any value (Other)
          Active:                 Yes
          First Page:             TestPage1
          Translation:            English-American
                                  Smart Script Assign
          Label:
                                  SR
3. Go to Smart Script Programs:
       1. Add the following code on Script Finish event:
          (When assigning an object it has to exist in order to match assignment
          rules, criteria and so on. On a newly created record during Smart Scripts
          execution, users can run BusinessComponent.WriteRecord() event before
          calling an assignment manager method in the SmartScript events to make
          sure that record exists in the database.)
               function Script_Finish()
               {
                   var sFirstQuestion = StartQuestion();
                   var SaveBC = sFirstQuestion.GetSaveBusComp();
                   TheApplication().Trace(" \n the value of
               sFirstQuestion =
               "+sFirstQuestion);
                        SaveBC.ActivateField("Area");
                        SaveBC.SetFieldValue("Area", "Upgrade");
               //*****************
                        var myid = SaveBC.GetFieldValue("Id");
                   SaveBC.WriteRecord();
                   var bsAmgr =
               TheApplication().GetService("Synchronous
               Assignment Manager Requests");
                   var psInput    =
               TheApplication().NewPropertySet();
                   var psOutput   =
               TheApplication().NewPropertySet();
                   psInput.SetProperty("AsgnObjName","Service
               Request");
               //Assignment Object Name
                   psInput.SetProperty("ObjRowId", myid);
               //Object Row ID
                   bsAmgr.InvokeMethod("Assign", psInput,
               psOutput);
               //*****************
               }
Technical Note 291: Calling a Shared Library from eScript
Last Modified:               4 November 2003
Area(s):                     Siebel VB/eScript/Browser Script/COM
Release(s):                  V6 (Siebel 2000-Enterprise), V7 (Enterprise)
Database(s):                 All Supported Databases
App Server OS(s):            Solaris, HP-UX
Latest release tested
                             V7 (Enterprise)
against:
Keywords:                      eScript, shared library, SElib.dynamicLink
Background
This technical note provides information about creating a shared library on Solaris or
AIX, and accessing it from Siebel eScript. Shared libraries on Solaris are similar to DLLs
on Windows. By implication, the eScript must run within a Siebel Server on Solaris, for
example, a business service called by a workflow process.
Summary
Shared Library
A shared library is a collection of functions that are compiled in a special manner. It does
not contain a main() function. It can be linked to any executable program. The Linker
does not include the code segments to the executable directly, but a path to the code
segment. This implies that the program using shared libraries is smaller than the same
program linked with the static version of those libraries.
Shared libraries are identified by their extension .so whereas static libraries have the
extension .a.
How to Create Shared Library on Solaris:
      Create a C file containing all the functions definition:
       Example: In libtest.c
       #include <string.h>
       void test(char *c)
             {
               strcpy(c, "This is a shared library
       function");
               return;
           }
      Compile and create a shared library using GNU compiler:
      gcc -c -fPIC -shared libtest.c -o libtest.o
      gcc libtest.o -shared -o libtest.so
       Where:
        -c        Compile or assemble the source files, but do not link.
                  The linking stage simply is not done. The ultimate
                  output is in the form of an object file for each source
                  file.
        -o        Place output in file.
        -shared   Produce a shared object which can then be linked with
                  other objects to form an executable.
        -fPIC     Generate position-independent code (PIC) suitable for
                  use in a shared library.
LD_LIBRARY_PATH
The LD_LIBRARY_PATH environment variable defines the path where the Siebel
server looks for the shared library file. After the installation of the Siebel server,
LD_LIBRARY_PATH points to the siebsrvr/lib directory. Copying the custom shared
library file into this directory will mean there is no need to change the
LD_LIBRARY_PATH environment variable.
In HP-UX, SHLIB_PATH environment variable defines the path where Siebel server
looks for most shared library files. When using SElib.dynamiclink in HP-UX, Siebel
will look for the shared library in LD_LIBRARY_PATH environment variable.
Use of Shared Library in eScript
eScript provides the SElib.dynamicLink() method to call a shared library file. Please
note that there are some differences between using this method for a Windows dll and a
shared library. There are some parameters, which are not used for shared library. For
example Calling Convention(CDECL, STDCALL..) is not used when calling a shared
library using the SElib.dynamicLink() method.
The syntax for calling a function within a shared library is:
SElib.dynamicLink(sharedlibrary name, function name, parameter1,
parameter2…)
Example:
      //Declare a variable
      var s;
            //Initialize a variable
            s = "                ";
            //Call shared library libtest.so, function test
            SElib.dynamicLink("libtest.so","test",s)
Important: There is no semi-colon at the end of the SElib statement.
Note: There should be no need to specify the complete path for a shared library as
LD_LIBRARY_PATH is already pointing to siebsrvr/lib, and the custom shared library
libtest.so exists in this directory. However, it may be necessary in some instances.
Technical Note 427: HTTP outgoing requests using Siebel Server Scripts
and Browser Scripts
Last Modified:               20 January 2003
Area(s):                     Siebel VB/eScript/Browser Script/COM, Siebel EAI
Release(s):                  V7 (Enterprise)
Database(s):                 DB2, Microsoft, Oracle
App Server OS(s):            AIX, Solaris, Windows NT, Windows 2000
Latest release tested
                             V7 (Enterprise)
against:
Keywords:                    HTTP Outgoing request, eScript, Siebel VB, Browser
                             Script, EAI HTTP Transport
Background
There are some situations where Siebel configurators need the ability to send HTTP
information back to external web systems, via http from within a script to confirm an
order or validate certain operations before the script can continue its normal execution.
There are different approaches to implement HTTP outgoing messages depending on the
type of scripting you have (Browser or Server script) and the type of Siebel client
running the script (Standard or High interactivity modes).
For the case of Browser and Server scripts and High Interactivity mode, users can use the
Siebel EAI HTTP Transport. For Low Interactivity mode, users can opt for a Java Script
based approach. Both these approaches are described in the next section.
Summary
From a scripting perspective, the Siebel EAI HTTP Transport can be used as a business
service providing both GET and POST methods for submitting the information to the
external system. It can be invoked either from Browser or Server script using similar
syntax, with the exception of the business service method invocation, where the Output
property is received differently in the Browser Script. See the examples section for more
details.
Another alternative in Standard Interactivity mode where business services are not
available in Browser Script is to use the Java Script Open method to construct an HTML
page on the fly, which posts the data to the external system.
Sample code
The sample code noted below presents both approaches, on invoking an ASP page and
passing to it two parameters: Data and Source using HTTP POST method.
Siebel eScript approach:
// Call EAI HTTP Transport
var sUrl = "http://localhost/testPost.asp";
var sRequest = "Data=MyTesting&Source=FromMyScripting";
var oService = TheApplication().GetService("EAI HTTP Transport");
var oInputs = TheApplication().NewPropertySet();
var oOutputs = TheApplication().NewPropertySet();
oInputs.SetProperty("HTTPRequestBodyTemplate", sRequest);
oInputs.SetProperty("HTTPRequestMethod", "POST");
oInputs.SetProperty("HTTPRequestURLTemplate", Url);
// Invoke EAI Service
oService.InvokeMethod("SendReceive", oInputs, oOutputs);
// Read Response Values (text)
var sResponse = oOutputs.GetValue();
Siebel VB approach:
Dim sUrl as string
Dim sRequest as string
Dim oService as Service
Dim oInputs as PropertySet
Dim oOutputs as PropertySet
Dim sResponse as string
'Call EAI HTTP Transport
sUrl = "http://localhost/testPost.asp"
sRequest = "Data=MyTesting&Source=FromMyScripting"
set oService = TheApplication().GetService("EAI HTTP Transport")
set oInputs = TheApplication().NewPropertySet()
set oOutputs = TheApplication().NewPropertySet()
oInputs.SetProperty "HTTPRequestBodyTemplate", sRequest
oInputs.SetProperty "HTTPRequestMethod", "POST"
oInputs.SetProperty "HTTPRequestURLTemplate", sUrl
' Invoke EAI Service
oService.InvokeMethod "SendReceive", oInputs, oOutputs
' Read Response Values
sResponse = oOutputs.GetValue()
Browser Script approach:
// Create a new IE window for the page
var oPostPage = window.open("", "Child",
config="height=60,width=70,toolbar=1,location=1,status=1,resizable=1");
// Build up the HTML page to post the data
oPostPage.document.write("<HTML><HEAD>");
oPostPage.document.write("<SCRIPT>");
oPostPage.document.write("function popup() {");
oPostPage.document.write(" document.frm1.submit(); }");
oPostPage.document.write("<\/SCRIPT><\/HEAD>");
oPostPage.document.write("<BODY>");
oPostPage.document.write(" This page is loading...");
oPostPage.document.write("** please WAIT **");
oPostPage.document.write("<FORM name='frm1' method='post'
action='http://localhost/testPost.asp'>");
// the parameters to pass
oPostPage.document.write("<input type='hidden' name='Data' value='MyTesting'>");
oPostPage.document.write("<input type='hidden' name='Source'
value='FromMyScripting'>");
oPostPage.document.write("<\/FORM>");
oPostPage.document.write("<\/BODY><\/HTML>");
// submit the data
oPostPage.document.frm1.submit();
If the Siebel application is running in High Interactivity mode the user can also invoke
the EAI HTTP Transport service to post the data, however this feature is not available on
low interactivity mode in which the previous approach cannot be used.
Browser Script (High Interactivity Mode only) approach:
// Call EAI HTTP Transport
var sUrl = "http://localhost/testPost.asp";
var sRequest = "Data=MyTesting&Source=FromMyScripting";
var oService = TheApplication().GetService("EAI HTTP Transport");
var oInputs = TheApplication().NewPropertySet();
var oOutputs = TheApplication().NewPropertySet();
oInputs.SetProperty("HTTPRequestBodyTemplate", sRequest);
oInputs.SetProperty("HTTPRequestMethod", "POST");
oInputs.SetProperty("HTTPRequestURLTemplate", sUrl);
// Invoke EAI Service
oOutputs = oService.InvokeMethod("SendReceive", oInputs);
// Read Response Values (text)
var sResponse = oOutputs.GetValue();
References
For additional information on the HTTP Transport methods please refer to the Transport
and Interfaces: Siebel eBusiness Application Integration Volume III guide, chapter 4
"EAI HTTP Transport".
Technical Note 207: Storing and Calling Global VB Functions Using DLLs
Last Modified:               11 November 1998
Area(s):                     Siebel VB/eScript/Browser Script/COM
Release(s):                  V5 (Siebel 99-Enterprise)
Database(s):                 All Supported Databases
App Server OS(s):            All Supported Platforms
Latest release tested
                             V5 (Siebel 99-Enterprise)
against:
Keywords:                    Global VB Functions, Using DLLs
Background
Siebel Visual Basic allows developers to create scripts on specific objects within the
repository, but does not directly support script sharing among objects – for example, the
use of global functions and subroutines. For configurations that require complex
functions or subroutines to be called in several different places, making several copies of
a script – one on each associated Siebel object – can present a huge maintenance
challenge.
The Siebel (COM) Application Server makes it possible for configuration teams to store
a function or subroutine in a .dll file and access it from any Siebel application object.
This approach simplifies the maintenance task and helps ensure that future changes to
key scripts are applied consistently throughout the application.
For cases in which the script has already been written in Siebel Visual Basic, the
approach begins with porting it over to a Microsoft Visual Basic .dll file. In order to
access Siebel application data and other state properties, the script will need to activate a
reference to the Siebel Application Server. Using the Siebel application server, the script
can then perform virtually all the same functions as Siebel Visual Basic, with a couple of
minor syntax changes. A few lines of Siebel Visual Basic (SVB) should be added to the
objects within Siebel applications that need to use the function. These will instantiate the
class, execute its methods and destroy it when done.
Summary
Porting the Script to Microsoft Visual Basic
Following steps will produce a .dll for storing the global function:
   1. Open Microsoft Visual Basic
   2. Choose Active X DLL from the New Project dialog box.
   3. Open the references dialog box by clicking on Project > References
   4. Add the Siebel Application Server class (also known as Siebel Business Object
      Interface) by checking the box next to it.
   5. Declare "SiebelApplication" as a public variable using the syntax:
Public SiebelApplication As SiebelApplication
   6. Under the Class Initialize event add the following line:
Set SiebelApplication = GetObject("", "SiebelAppServer.ApplicationObject")
   7. Add a public subroutine header using the following syntax:
"Public Sub [Name of Subroutine] (arg1, arg2, etc.)"
This technical note shows an example that uses a subroutine called "Aggregate" which
takes two arguments: parentfield and childfield. Its declaration appears as:
"Public Sub Aggregate (parentfield, childfield)"
   8. Declare the local variable "errCode" as an integer.
   9. Add the script to be run in the global function. If the script was originally written
      inside a Siebel application, be sure to change from "TheApplication.[method]" to
      "SiebelApplication.[Method]. Also, keep in mind that "errCode" is a required
      argument for Siebel application methods that belong to objects inside the
      Application Server. Modify the names of Siebel application object types to
      conform to the syntax used by the Siebel Application Server. For example:
Siebel Visual Basic DLL
TheApplication.BusObject > SiebelApplication.SiebelBusObject
BusObject.BusComp > SiebelBusObject.SiebelBusComp
Etc.
   10. Under the Class Terminate event, add the following line:
Set SiebelApplication = Nothing
   11. After writing the function, change the name of the project from the default
       "Project1" to something more appropriate (later this will help in referring to the
       class object.). To do this, go to the Project Explorer window (this can be accessed
       by clicking View > Project Explorer, if it’s not already open). Select the project
       object with the default name "Project1." From here, go to the Properties window
       and type the name in the "(Name)" property (example: "GlobalFunction")
   12. Change the name of the class object to something that’s consistent with its
       purpose (example: "StringManager") using the steps outlined above.
   13. Compile the .dll file by selecting File > Make Project1.dll. When this item is
       selected, a dialog box for saving the .dll file under any name (that is, the name
       can be changed from the default "Project1.dll") will be seen. When the name and
       location of the .dll file is chosen, click "OK."
   14. Save the project and exit Visual Basic.
Call the function from within the Siebel application
   1. In Siebel Tools, navigate to the object and event from where the script is to be
      called.
   2. Declare an object variable for referring to an instance of the class using the
      syntax:
Dim MyStringManager as Object
   3. Instantiate the class and set the object variable using the syntax in the following
      example:
Set MyStringManager = CreateObject("GlobalFunction.StringManager")
   4. Call the function in the .dll (example: "Aggregate") using the syntax in the
      following example:
MyStringManager.Aggregate "Service Request Description","Service Request Activity
Notes"
   5. Destroy the object using the syntax in the following example:
Set MyStringManager = Nothing
Example
The code in the following example was designed to concatenate the notes from several
child records into a summary description field of a parent record. The SVB calling this
routine would logically reside on both the WriteRecord and DeleteRecord events of the
child business component, so that any time one of the child records changed, the parent
summary would be updated.
Text from Siebel Visual Basic subroutine
Sub Aggregate(parentfield As String, childfield As String)
Dim Notes As String
Dim childbc As BusComp
Dim parentbc As BusComp
Set childbc = me.buscomp
Set parentbc = childbc.ParentBusComp
If childbc.FirstRecord Then
Notes = "["
Do
Notes = Notes & Left(childbc.GetFieldValue("Created"), 11) & "]" & Chr(32) & Chr(32)
Notes = Notes & childbc.GetFieldValue(childfield) & Chr(13) & Chr(10)
If childbc.NextRecord = False Then
Exit Do
End If
Loop
parentbc.ActivateField parentfield
parentbc.SetFieldValue parentfield, Notes
parentbc.WriteRecord
parentbc.DeactivateFields
End If
Set parentbc = Nothing
Set childbc = Nothing
End Sub
Text from Microsoft Visual Basic project
Public SiebelApplication As Object
Public Sub Aggregate(parentfield As String, childfield As String)
Dim Notes As String
Dim childbc As SiebelBusComp
Dim parentbc As SiebelBusComp
Dim errCode As Integer
Set childbc = SiebelApplication.ActiveBusComp(errCode)
Set parentbc = childbc.ParentBusComp(errCode)
If childbc.FirstRecord(errCode) Then
Notes = "["
Do
Notes = Notes & Left(childbc.GetFieldValue("Created", errCode), 11) & "]" &
Chr(32) & Chr(32)
Notes = Notes & childbc.GetFieldValue(childfield, errCode) & Chr(13) & Chr(10)
If childbc.NextRecord(errCode) = False Then
Exit Do
End If
Loop
parentbc.ActivateField parentfield, errCode
parentbc.SetFieldValue parentfield, Notes, errCode
parentbc.WriteRecord errCode
parentbc.DeactivateFields errCode
End If
Set parentbc = Nothing
Set childbc = Nothing
End Sub
Private Sub Class_Initialize()
Set SiebelApplication = GetObject("", "SiebelAppServer.ApplicationObject")
End Sub
Private Sub Class_Terminate()
Set SiebelApplication = Nothing
End Sub
Visual Basic project bitmap