Sie sind auf Seite 1von 3

Siebel Scripting CancelOperation or ContinueOperation

This article explains the concept of returning CancelOperation and ContinueOperation in Siebel Scripting. Go to Siebel Tools > Object Explorer > Business Component. Select any business component and lock the project (Tools > Lock Project). Then Right click any business component and left click 'Edit Server Scripts' from the right click menu to view the server scripts. Now if you click on any server script event method that is like BusComp_Pre* you will see that the method contains 'return (ContinueOperation)'. The first thing to note is that business component and applet server script only requires return (ContinueOperation) or return (CancelOperation) if it is a 'Pre' method. For example PreInvokeMethod, PreSetFieldValue, PreWriteRecord. ContinueOperation and CancelOperation and constant integers that are global to Siebel. In these 'Pre' event methods, if you return ContinueOperation then the method to follow will be invoked, if you return CancelOperation then the method to follow will not be invoked. For example on PreWriteRecord if you return ContinueOperation then the WriteRecord will occur, otherwise CancelOperation will cause the WriteRecord to not occur. The same is applied for PreInvokeMethod, if CancelOperation is returned then the method (whatever it may be) will not be invoked. For any 'Pre' event methods, CancelOperation and ContinueOperation MUST be returned. It is also best practice to ensure that only one return statement exists in an event method. Therefore it is best practice to declare a return variable and assign the value of CancelOperation or ContinueOperation to this variable based on your code. An example is shown below of how you would implement this using best practices. So now we know about the 'Pre' event methods such as PreSetFieldValue and PreWriteRecord is the event method executed prior to the actual SetFieldValue and WriteRecord respectively. The PreInvokeMethod is abit different. The PreInvokeMethod is the event method fired prior to a particular method being invoked. For example when the user clicks a glyph on a pick applet field or MVG field the 'EditField' method is invoked. If you look at the PreInvokeMethod field on some server script you will notice that the MethodName is passed as a variable input argument to the function. So this event method is fired any time a method is invoked and the method name is passed as input to the function as the MethodName variable. In the PreInvokeMethod function you could write script that would check the MethodName variable to execute code for a particular method. This is useful if you create a custom method on a button, when the button is clicked the PreInvokeMethod event method is fired and the custom method name is passed as input. Then you can check for the custom method name in the MethodName variable and execute your custom code returning CancelOperation to ensure that Siebel does not try to internally invoke the method.

The example below shows that for all custom methods that CancelOperation must be returned because if ContinueOperation was returned, the internal Siebel functions for that object would not recognize the method and would throw an error. However for methods such as NewRecord or EditField these methods are build into Siebel objects and would be recognised by Siebel and hence ContinueOperation could be returned to allow the method to be invoked internally by Siebel.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: function BusComp_PreInvokeMethod (MethodName) { var sReturn = ContinueOperation; try { switch (MethodName) { case "EditField": //execute your code here //..... //now check for error condition to //cancel or continue the operation //for this example the condition //results in CancelOperation if (1==0) { sReturn = CancelOperation; } else { sReturn = ContinueOperation; } break; case "TestMethod": //execute code for this custom method //and ensure that CancelOperation is returned //.... sReturn = CancelOperation; break; case default: sReturn = ContinueOperation; break; } } catch(e) { sReturn = CancelOperation; TheApplication().RaiseErrorText(e.toString()); } finally { } return (sReturn); }

From the above example we can see that the PreInvokeMethod is useful in the fact that it can be used to execute code before an inbuilt method (such as NewRecord or EditField) is invoked and can also be used to execute code for a custom method and stop Siebel from trying to invoke that method internally. The same logic for CancelOperation and ContinueOperation applies for browser script event methods. However the difference is that you return the method as a string value rather than the constant. For example the return statement would look like this: return (CancelOperation);

Das könnte Ihnen auch gefallen