Examples Escript
Examples Escript
• function Applet_ChangeRecord ()
{
try
{
var thisBC = this.BusComp();
var sFlag = thisBC.GetFieldValue("Primary Revenue Committed
Flag");
if (sFlag == "Y")
{
alert("This record cannot be update as its been Committed");
}
}
catch(e)
{
alert("Error in ChangeFieldValue and error is " + e.toString() + " "
+ e.errText());
}
}
The PreInvokeMethod event is called before a specialized method
is invoked, by a user-defined applet menu, or by calling
InvokeMethod on an applet.
• function BusComp_SetFieldValue
(FieldName)
{
if (FieldName == "Type" &&
GetFieldValue(FieldName) == "Account")
{
SetFieldValue("Description", "Record
is of Type 'Account'." );
}
}
Business service
• Business Service Events
• Service_InvokeMethod Event
• Service_PreCanInvokeMethod Event
• Service_PreInvokeMethod Event
• This Browser Script example invokes
the Shipping Engine business service
created in Service_PreInvokeMethod
Event in response to a button click.
The InvokeMethod property on the
Button is set to "CalcShipping". It gets
values from the keyboard through
prompts (JavaScript method), passes
a property set to the service, and gets
return values by means of another
property set.
• function Applet_PreInvokeMethod (name,
inputPropSet)
• {
if (name == "CalcShipping") {
var svc = theApplication().GetService("Shipping
Engine");
var inputs = theApplication().NewPropertySet();
var outputs = theApplication().NewPropertySet();
• var size = prompt("Enter the sum of H+W+D in
inches");
var shipper = prompt("Enter the shipping
company");
var weight = prompt("Enter the shipping weight in
pounds");
• with (inputs) {
SetProperty ("Size", size);
SetProperty ("Shipping Company", shipper);
SetProperty ("Ship Method", shipMethod);
SetProperty ("Weight", weight);
}
• outputs = svc.InvokeMethod("CalculateShipping",
inputs);
var cost = outputs.GetProperty("Cost");
var delDate = outputs.GetProperty("Delivery Date");
• TheApplication().SWEAlert ("Shipping by " + shipper +
":\n Shipping Cost is " +
cost + ",\n Estimated delivery date is " +
delDate);
• return (CancelOperation);
• }
• else
• return (ContinueOperation);
• }
• This Siebel VB example creates the new service
"Shipping Engine."
• Function Service_PreInvokeMethod (MethodName As
String, Inputs As PropertySet, Outputs As PropertySet)
As Integer
• If MethodName = "CalculateShipping" Then
• Dim sShipper As String, sShipMethod As String
Dim dWeight As Double, dSize As Double, dCost As
Double
Dim sZone As String, DelDate As Variant
Dim sCost As String, iReturn As Integer
• iReturn = ContinueOperation
sShipper = Inputs.GetProperty("Shipping Company")
sShipMethod = Inputs.GetProperty("Ship Method")
dWeight = Val(Inputs.GetProperty("Weight"))
dSize = Val(Inputs.GetProperty("Total Dimensions"))
iZone = Val(Inputs.GetProperty("Zone"))
DelDate = DateValue(Now)
• Select Case sShipper
Case "GlobalEx"
Select Case sShipMethod
Case "Next-Day Air"
dCost = 14 + dWeight
DelDate = DelDate + 1
Case "Second-Day Air"
dCost = 11 + (dWeight * .54)
DelDate = DelDate + 2
End Select
• Case "Airline"
Select Case sShipMethod
Case "Next-Day Air"
dCost = 5 + (dWeight * .3) + (dSize * .33) + _
(Val(sZone) * .5)
DelDate = DelDate + 1
Case "Second-Day Air"
dCost = 4 + (dWeight * .3) + (dSize * .2) + _
(Val(sZone) * .3)
DelDate = DelDate + 2
•
• Case "Ground"
dCost = 3 + (dWeight * .18) + (dSize * .1) + _
(Val(sZone) * .1)
DelDate = DelDate + 2 + Int(Val(sZone) * .8)
End Select
End Select
• sCost = Format(dCost, "Currency")
Outputs.SetProperty "Cost", sCost
Outputs.SetProperty "Delivery Date", DelDate
iReturn = CancelOperation
• End If
• Service_PreInvokeMethod = iReturn
• End Function
• This Siebel VB example creates the new service "Shipping Engine."
• Function Service_PreInvokeMethod (MethodName As String, Inputs As PropertySet, Outputs As PropertySet) As Integer
• If MethodName = "CalculateShipping" Then
• Dim sShipper As String, sShipMethod As String
Dim dWeight As Double, dSize As Double, dCost As Double
Dim sZone As String, DelDate As Variant
Dim sCost As String, iReturn As Integer
• iReturn = ContinueOperation
sShipper = Inputs.GetProperty("Shipping Company")
sShipMethod = Inputs.GetProperty("Ship Method")
dWeight = Val(Inputs.GetProperty("Weight"))
dSize = Val(Inputs.GetProperty("Total Dimensions"))
iZone = Val(Inputs.GetProperty("Zone"))
DelDate = DateValue(Now) Select Case sShipper
Case "GlobalEx"
Select Case sShipMethod
Case "Next-Day Air"
dCost = 14 + dWeight
DelDate = DelDate + 1
Case "Second-Day Air"
dCost = 11 + (dWeight * .54)
DelDate = DelDate + 2
End Select
• Case "Airline"
Select Case sShipMethod
Case "Next-Day Air"
dCost = 5 + (dWeight * .3) + (dSize * .33) + _
(Val(sZone) * .5)
DelDate = DelDate + 1
Case "Second-Day Air"
dCost = 4 + (dWeight * .3) + (dSize * .2) + _
(Val(sZone) * .3)
DelDate = DelDate + 2
• Case "Ground"
dCost = 3 + (dWeight * .18) + (dSize * .1) + _
(Val(sZone) * .1)
DelDate = DelDate + 2 + Int(Val(sZone) * .8)
End Select
End Select
• sCost = Format(dCost, "Currency")
Outputs.SetProperty "Cost", sCost
Outputs.SetProperty "Delivery Date", DelDate
iReturn = CancelOperation
• End If
• Service_PreInvokeMethod = iReturn
• End Function
• The PreCanInvokeMethod event is called
before the PreInvokeMethod, allowing the
developer to determine whether or not the
user has the authority to invoke the
business service method. The
Advanced Example & Workflow
• Within a workflow process, you can store a
property set in a process property of type
Hierarchy. To pass the content of a
process property to or from a custom
business service, however, the Type of the
child property set stored in the process
property must match the name of the input
or output argument of the business
service.