Wednesday, June 25, 2008

Browser Scripting

Browser Script is script that is run in the client application.It is more efficient to run browser script than server script in most cases, but the drawback is that browser script cannot accomplish as much as server script.

Browser script is commonly used for the following functions:

  • Modifying parts of the UI dynamically (i.e. font colors or sizes, etc.).
  • Exposing or hiding form applet controls.
  • Working with ActiveX objects (such as interacting with another application).
  • Showing alerts or popup windows.
  • Invoking business services.
  • Obtaining input from the user.
There are some important limitations to browser scripting:

  • There are no Query operations. All operations in browser script act on the current context.
  • You cannot use Virtual Basic (VB) in browser scripting, only eScript (since it is based on JavaScript).
  • The only fields available for use in browser script are the Id field and any field that is visible in the UI. Hidden fields and fields not mapped to a web template cannot be referenced.
  • You cannot use the built-in Siebel Tools debugger with browser script. It will ignore any breakpoints you place.

Goal

We will create a MiniButton control on the ‘Contact List Applet’ applet that, when clicked, will display a ‘Welcome India!’ message to the user.

Solution

we must first configure Siebel Tools to compile browser scripts into the proper location.So, Login to the Siebel Tools
Choose View > Options. Click on the ‘Scripting’ tab.
In the ‘Browser script compilation folder:’ textbox, enter in the correct path "D:\sea78\client\PUBLIC\enu." for compilation.

Configuration steps:

1. Login to Siebel Tools
2. In Object Explorer, select the ‘Applet’ object.
3. Query for ‘Contact List Applet’.
4. Right-click the Contact List Applet, and then select ‘Lock Object’.
5. In Object Explorer, click the ‘+’ next to the Applet object to expand it.
6. Select the Control child-object.
7. Create a new record with the following values:
a. Name: welcome
b. Caption – String Override: Welcome
c. HTML Type: MiniButton
d. Method Invoked: India
9. In the Applets window, right click the ‘Contact Applet’ applet, and select ‘Edit Web Layout’.
10. Change the Mode to ‘3: Edit List’.
11. Select the ‘welcome’ button and drag it onto the Applet.
12. Save and exit out of the Applet web layout editor.

We are now ready to enable our button declaratively. Do so by completing the following steps:

1. Select the ‘Applet’ object and query for the ‘Contact List Applet’ applet.
2. Select the ‘Applet User Prop’ child object of applet in Object Explorer.
3. Create a new record with the following values:
Name: CanInvokeMethod: India
Value: TRUE
4. Select the 'Contact List Applet'.
5. Right-click the applet and select ‘Edit Browser Scripts’ and select eScript as the scripting language to be used.
7. Under ‘BrowserApplet’, select the ‘Applet_PreInvokeMethod’ event. This is the event where our code will take place.

Sample Code:

function AppletPreInvokeMethod (Name,inputPropSet)
{

If (name=="India")
{
theApplication().SWEAlert("Welcome India");
return(CancelOperation);
}
return(ContinueOperation);
}

8. Save and exit the script.

Server Script Example:

Goal

We Access Data from a Parent-Child Relationship Using Scripting.

Solution

Parent-child relationships are defined through links and multi-value links in Siebel Tools. Depending on how the relationship is defined, a different approach is used to access the data using scripting, but in general it follows the same rules as the user interface does.
Multi-value links (MVLs) and multi-value fields (MVFs) are used when child data needs to be presented on the same applet as the parent data. On the other hand, a link definition is enough when child data is presented on a different applet than the parent data, but in the same view.

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

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.

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