Example of Using Siebel VB to Create a Validation
The following Siebel VB example creates a validation that queries a specific field to determine if the object interface event completed successfully or completed with a run-time error:
Function BusComp_PreSetFieldValue (FieldName As String,
FieldValue As String) As Integer
' code to check if a quote discount > 20%
' if it is, notify user and cancel the operation
Dim value as Integer
Dim msgtext as String
If FieldName = "Discount" then
value = Val(FieldValue)
If value > 20 then
msgtext = "Discounts greater than 20% must be approved"
TheApplication.RaiseErrorText msgtext ' cancels the run
Else
BusComp_PreSetFieldValue = ContinueOperation
End if
End If
End Function
Note the If statement in the following pseudocode:
If condition is true
call custom code
raise error text to cancel operation
Else
returnValue = ContinueOperation
End If
In this If statement, Siebel CRM runs the custom code only if the condition is true:
If the condition is true, then Siebel CRM uses the custom code instead of the predefined code.
If the condition is not true, then the event handler returns ContinueOperation, and Siebel CRM uses the predefined code.
You can also use the following alternative If statement:
returnValue = Continue Operation
If condition is true
call custom code
End If
Note that with a PreInvokeMethod event, you use the method name to determine if the script conditionally runs. For example, consider the following code in Siebel eScript:
if (methodName == "PushOpportunity")