Search This Blog

May 26, 2011

Siebel eScript

*************************************
     Server Scrpit UI Context
*************************************
----------------------------------------------------------------------------------------------------------------------
-- validate Account Name (BusComp_PreWriteRecord) on Account BC
    var min = 5;  
    var max = 12;  
    var len;  
    var n = 0;  
    var lname = this.GetFieldValue("Name");
    var flen = lname.length;  
  
    if(flen < min)  
    {          
        TheApplication().RaiseErrorText("Account name should be more than 4 characters");  
    }      
  
    if(flen > max)  
    {
        TheApplication().RaiseErrorText("Account name should not have more than 12 characters");  
    }  

    var rStrcspn = Clib.strcspn(lname,"1234567890");
  
    if(rStrcspn < flen)  
    {
        TheApplication().RaiseErrorText("Account name should not any number");
    }

- Right Click on the Account Business Component and Compile It.
---------------------------------------------------------------------------------------------------------------------
-- Set the JOb Field Value to Employee Whenever any New Record is Create on Contact BC.
1 - Select the Contact Business Component and Lock the it.
2 - Right and Select Edit Server Script Option.
3 - Select Function -  (BusComp_SetFieldValue (FieldName)) .
4 - Write the following script.
-- set the job field value.
    var defJob = "Employee";  
    this.SetFieldValue("Job Title",defJob);

5- Right Click on the Contact Business Component and Compile It.
6- Open Siebel web client and go to Conact create a new record to test it.
---------------------------------------------------------------------------------------------------------------------
-- Do not allow to delete the account if the status is Active.
1 - Select the Account Business Component and Lock the it.
2 - Right and Select Edit Server Script Option.
3 - Select Function -  BusComp_PreDeleteRecord
4 - Write the following script.

function BusComp_PreDeleteRecord ()
{
    var status = this.GetFieldValue("Account Status")
    if(status == "Active")
    {
        TheApplication().RaiseErrorText("You can not delete this account as its a Active account.");                  
        return (CancelOperation);
    }
    else
    {
        return (ContinueOperation);
    }
}

5- Right Click on the Account Business Component and Compile It.
---------------------------------------------------------------------------------------------------------------------
-- Do not allow to change the account status if current volume is greater than 0.
1 - Select the Account Business Component and Lock the it.
2 - Right and Select Edit Server Script Option.
3 - Select Function -  BusComp_PreSetFieldValue
4 - Write the following script.

function BusComp_PreSetFieldValue (fieldName, value)
{

   if (fieldName == "Account Status")
   {
      var cVolume = this.GetFieldValue("Current Volume");

      if ((value == "Inactive") && (cVolume > 0))
      {
         TheApplication().RaiseErrorText("Unable to inactivate an account that has a current volume greater than 0");
         return ("CancelOperation");
      }
      else
         return ("ContinueOperation");
   }
   else
      return ("ContinueOperation");
}
---------------------------------------------------------------------------------------------------
-- Write Script to Call Server Script on User Define Button.
Server Script with Applet Button :

1 - Check the current volumn field value on the button click using the server script.

1) Goto Applet Query for Account Entry Applet
2) Right Click and Edit Web Layout and Drag a MiniButton from Palette window to Applet.
3) Right Click the Button and goto Property window.
    -- Change the following peroperties.
    -- Caption-String Overriden : Check Volume
    -- Runtime  = TRUE
    -- MethodName = CheckVol

4) Save the changes and close the web layout.
5) Now Right the method to enable the button on applet.
6) Right click on Account Entry Applet and click on Edit Server Script.
7) Goto WebApplet_CanPreInvoke Method and write the following script.

    // enable the button on applet
    if(MethodName == "CheckVol")
    {
        CanInvoke="TRUE";
        return (CancelOperation);
    }
    return (ContinueOperation);

8) Now we will be writting a function to call on the button click.
9) Query for the Business Component Account and Right Click select Edit Server Script.
10) Goto BusComp_PreInvokeMethod method and write the following script.

function BusComp_PreInvokeMethod (MethodName)
{
    var vol = this.GetFieldValue("Current Volume");

    if( vol > 0 )
    {
        TheApplication().RaiseErrorText("Volumn exist for this account. Volumn = " + vol);
        return (CancelOperation);
    }
    else
    {
        TheApplication().RaiseErrorText("Volumn does not exist for this account.");
        return (ContinueOperation);
    }
}
----------------------------------------------------------------------------------------------------------
*************************************
    Server Scrpit Non UI Context
*************************************

-- Do not allow to delete the account if an opportunity is exist for the account.
1 - Select the Account Business Component and Lock the it.
2 - Right and Select Edit Server Script Option.
3 - Select Function - BusComp_PreDeleteRecord.
4 - Write the following script.

TheApplication().TraceOn("c:\temp\opp_trace.txt","Allocation","All");
var returnCode = ContinueOperation;

try
{
    //get the BO and BC first for the Opporunity.
    var boOpty;
    var bcOpty;
    var rowID;
    // get the rowid
    rowID = this.GetFieldValue("Id");


    // create the business object using GetBusObject method.
    boOpty = TheApplication().GetBusObject("Opporunity");
    bcOpty = boOpty.GetBusComp("Opporunity");

    // trace the operation
    TheApplication().Trace("Preparing Query");
  
    with(bcOpty)
    {
        SetViewMode(ViewAll);
        ActivateField("Account Id"); // must activate the field before the cleartoquery method.
        ClearToQuery(); // clears the current query.
        SetSearchExpr("[Account Id]= '"+rowID+"'");
        ExecuteQuery(ForwardOnly);
    }
    TheApplication().Trace("Query Executed.");
  
    if(bcOpty.FirstRecord())
    {
        returnCode = CancelOperation;
        TheApplication().RaiseErrorText("Opp is exist for this Account. It can not be deleted.");
    }
    else
    {
        returncode = ContinueOperation;
    }
}
catch(e)
{
    throw(e); //display error message to user
}
finally
{
    delete bcOpty;
    delete boOpty;
    TheApplication().TraceOff();
}
return (returncode);
------------------------------------------------------------------------------------------------------------
*************************************
            Browser Scrpit
*************************************

** Display the confirmation of the changing the account status from any other to active status.
1 - Select Applet in the Object List Expolrer.
2 - Select Account List Applet.
3 - Right Click on the Opportunity List Applet.
4 - select Edit Browser Scritp.
5 - Select Applet_ChangeRecord.
6 - Write the following script.
  
function Applet_ChangeFieldValue (field, value)
{
    //var status = this.FindControl("Account Status");
    if(field == "Account Status")
    {
        if(value == "Active")
        {
            var ans = confirm("are you sure you wnat to change status of this account");
            if(ans == true)
              return (ContinueOperation);
            else
              return (CancelOperation);             
        }
    }
}
7 - set the compile direcotry path using View - Option - Scripting
   - browswer script compilation folder : D:\siebel81\Client\PUBLIC\enu
----------------------------------------------------------------------------------------------------------------
Ex2 - Broswer Script
** Make the controls read only on the applet if the Service Request status is Cancelled.
1 - Select Applet in the Object List Expolrer.
2 - Select Service Request Detail Applet.
3 - Right Click on the Service Request Detail Applet.
4 - select Edit Browser Scritp.
5 - Select Applet_ChangeFieldValue(field,value)
6 - Write the following script.

if(field == "Status")
{      
    if(value=="Cancelled")  
    {      
        var tmp = this.FindControl("CommitTime");                                          
        tmp.SetProperty("ReadOnly",true);
        tmp = this.FindControl("ContactLastName");
        tmp.SetProperty("ReadOnly",true);
        tmp = this.FindControl("Account");                                              
        tmp.SetProperty("ReadOnly",true);              
        tmp = this.FindControl("Product");                                              
        tmp.SetProperty("ReadOnly",true);
        tmp = this.FindControl("Description");                                              
        tmp.SetProperty("ReadOnly",true);
        tmp = this.FindControl("Abstract");
        tmp.SetProperty("ReadOnly",true);      
    }
    else
    {
        var tmp = this.FindControl("CommitTime");
        tmp.SetProperty("ReadOnly",false);
        tmp = this.FindControl("ContactLastName");
        tmp.SetProperty("ReadOnly",false);
        tmp = this.FindControl("Account");
        tmp.SetProperty("ReadOnly",false);
        tmp = this.FindControl("Product");
        tmp.SetProperty("ReadOnly",false);
        tmp = this.FindControl("Description");
        tmp.SetProperty("ReadOnly",false);  
        tmp = this.FindControl("Abstract");                                              
        tmp.SetProperty("ReadOnly",false);      
    }
}
-----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
-- Write a Browser script to Prompt a Message to user on the New Record creation ask to enter a value to continue. ( Value : Y || N )
1 - Select Applet Object Type in OE.
2 - Select Account List Applet in OBLE.
3 - Right Click on Account List Applet.
4 - Select Edit Browser Script.
5 - It will show the functions and three Modes of Applet.
  - Select function Applet_PreInvokeMethod and write the following Script.


function Applet_PreInvokeMethod (name, inputPropSet)
{
    if(name == "NewRecord")
    {
        var ans = prompt("Y to Create Record & N to Exit \n Enter a Value : ");  
        if(ans == "Y")
        {
            theApplication().SWEAlert("Please fill the records .....");
            return ("ContinueOperation");
        }
        if(ans == "N")
        {
            alert("Operation Cancelled.");
            return ("CancelOperation");
        }
    }
}
--------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
-- Write a Browser script to Prompt a Message to user on the New Record creation ask to enter a value to continue. ( Value : Y || N )
1 - Select Applet Object Type in OE.
2 - Select Account List Applet in OBLE.
3 - Right Click on Account List Applet.
4 - Select Edit Browser Script.
5 - It will show the functions and three Modes of Applet.
  - Select function Applet_PreInvokeMethod and write the following Script.


function Applet_PreInvokeMethod (name, inputPropSet)
{
    if(name == "NewRecord")
    {
        var ans = prompt("Y to Create Record & N to Exit \n Enter a Value : ");  
        if(ans == "Y")
        {
            theApplication().SWEAlert("Please fill the records .....");
            return ("ContinueOperation");
        }
        if(ans == "N")
        {
            alert("Operation Cancelled.");
            return ("CancelOperation");
        }
    }
}
-----------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------
-- Create a Button on Applet and Export to Account Names to Excel using DOM Object.

1 - Select Applet Object Type in OE.
2 - Select Account List Applet in OBLE.
3 - Right Click on Account List Applet.
4 - Select Edit Web Layout
  - It will show the functions and three Modes of Applet.
5 - Select Edit List Mode and Add a button to Applet and Change the following properties ;
    - Caption String Override : Export 2 Excel
    - Method Invoke : Export
    - Runtime : TRUE.

6 - Save the applet and close the web layout.
7 - Select Account List Applet and Right Click Select Edit Server Script.
  - this step will enable the button on applet.
  Select function WebApplet_CanPreInvokeMethod and write the following Script.
    function WebApplet_PreCanInvokeMethod (MethodName, &CanInvoke)
    {
        if(MethodName=="Export")
        {
            CanInvoke = "True";
            return (CancelOperation);
        }
        return (ContinueOperation);
}
- Save the script and Close the window.
8 - Select Applet Object Type in OE.
9 - Select Account List Applet in OBLE.
10 - Right Click on Account List Applet.
11 - Select Edit Browser Script.
12 - It will show the functions and three Modes of Applet.
  - Select function Applet_PreInvokeMethod and write the following Script.
Write the Following Script.

function BusComp_PreInvokeMethod (MethodName)
{
    var ExcelApp;

   if(MethodName == "Export")
   {

        this.ActivateField("Name");
         this.SetSearchSpec ("Name","*");
        this.ExecuteQuery(ForwardBackward);

        var count = this.CountRecords();

        ExcelApp = this.COMCreateObject("Excel.Application");
           ExcelApp.Visible = true;
           ExcelApp.WorkBooks.Add();
     
        this.FirstRecord();     

           for(var i=1;i<=count;i++)
           {
              ExcelApp.ActiveSheet.Cells(i,1).Value = this.GetFieldValue("Name");
               ExcelApp.ActiveSheet.Cells(i,2).Value = this.GetFieldValue("City");
               ExcelApp.ActiveSheet.Cells(i,3).Value = this.GetFieldValue("Account Status");
               this.NextRecord();
          }
      
        ExcelApp.Application.Quit();
           ExcelApp = null;
       }
    return (CancelOperation);


-------------------------------------------------------------------------------------------------------

1 comment:

Siebel IP 2017 - Web Tool Development Steps

Siebel IP 2017 Development and Deployment Steps : 1. Click on the Workspace Icon in Siebel Web Tools application. 2. Create a New work s...