Sep 28, 2008

Enabling n disabling a Button

Enabling n disabling a Button

There are two methods used to enable or disable buttons. One involves configuration and the other involves scripting. The complexity of the logic surrounding the button state drives which approach to take.

Steps

  1. Examine the logic required to enable the button.
    1. If the logic is unconditional (for example, always display the My Method button) then use the configuration method.
    2. If the logic is conditional (for example, only enable the Close SR button if all child activities are Completed on satisfying a condition) then use the scripting method.

Configuration Method

                                   The configuration method can be applied either at the Applet or Business Component level. Think carefully about where to place the configuration. If it will be needed in many applets based on one BC, then it is probably best to place it directly on the BC. If it is only likely to be needed for a single applet, then you may feel it is more appropriate to enable the method only on the Applet.

Applet Level

  1. Create a new Applet User Property called

"Named Method: Method Name" where Method Name is the name of the method being enabled.

  1. Set the value of this user property to be 'INVOKE', 'MethodName' where MethodName is the name of the method being enabled.

BC Level

  1. Create a new BC User Property called "Named Method X" where X is a sequential number (starting from 1).
  2. Set the value of this user property to be "MethodName", "INVOKE", "BC", "MethodName" where MethodName is the name of the method being enabled and BC is the name of the business component on which it is enabled.

Scripting Method

The scripting method is applicable when the logic needed to enable or disable the button is complex (for example if you have to check or satisfy a field value)

  1. Edit the Server script on the Applet
  2. Within the WebApplet_PreCanInvokeMethod function enter script for the method that you need to enable.
    • Note that it's essential to minimize any script placed in the WebApplet_PreCanInvokeMethod event handler as this function is called a lot of times!

2.      If the button is to be enabled the CanInvoke parameter must be set to "True" (Note this must be "TRUE" in some versions)

3.      If the button is to be disabled the CanInvoke parameter must be set to "False" (Note this must be "FALSE" in some versions)

  1. If you have finished processing the logic, then return Cancel Operation.
  2. If the internal Siebel classes also need to process this request (for example if you're modifying the behavior of Write Record), then you may need to return Continue Operation.
  3. Ensure that the script returns ContinueOperation for all methods that you haven't explicitly dealt with.

Examples

To enable a button invoking the "MyMethod" method on the Service Request List Applet.

Configuration Method

Assuming that the button is to be enabled unconditionally.

Applet Level

  1. On the Service Request List Applet create a new User Property called "Named Method: MyMethod".
    • Set the value of this property to 'INVOKE', 'MyMethod'

BC Level

  1. On the Service Request BC create a new User Property called "Named Method 1". Note that the number 1 represents the appropriate value for the 7.7 Sample database for the Service Request BC. Ensure that you check the appropriate value for yourself.
    • Set the value of this property to "MyMethod", "INVOKE", "Service Request", "MyMethod".

 Scripting Method

If the button is to only be enabled if the Status field is set to "Completed".

eScript

function WebApplet_PreCanInvokeMethod (MethodName, &CanInvoke)
{
  switch(MethodName)
  {
     case "MyMethod":
 
        //The status field has Link Specification set to True so it will always be     Active, so does not require additional code to acitvate and retreive the value.
 
        if(this.BusComp().GetFieldValue("Status")=="Completed")
           CanInvoke = "True";
        else
           CanInvoke = "False";
        return(CancelOperation);
        break;
     default:
        return(ContinueOperation);
  }

               There is one more way to enable the method Methods that use the naming format EventMethodxxx do not require any applet or business component script to enable the event. for example, if we set MethodInvoked='EventMethodTestMethod' you need not use a userpropery

}

No comments: