Search This Blog

Showing posts with label Siebel eScript. Show all posts
Showing posts with label Siebel eScript. Show all posts

Sep 28, 2016

Message Category in Siebel


What is Message Category in Siebel?
Messages can be combined with message categories for easier classification. We can reference the messages in custom scripts, enabling us to adhere to professional programming standards by avoiding hardcoded text in the program.
How to Enable the Message Category in Siebel?
View -> Options -> Object Explorer -> Message Category
           
 What is Lookup Message in Siebel?
The LookupMessage method returns the translated string for the specified key, in the current language, from the specified category. The optional arguments are used to format the string if it contains any substitution arguments (%1,%2).
  • Place a button on Applet


  • Fill the following Property
 
  • Write a Script on Applet to enable the button for an Action.
  • Now Compile the Applet.
  • Now Lets Define the Message Category in Siebel.

  • Now let’s write a script and call this Message category. 
  • Move to Business Component and Query for Account
 
  • Write a Server Script on BC.
 
  • Now compile the changes and Test it.

Oct 22, 2012

SetNamedSearch Method



SetNamedSearch Method

How to use SetNamedSearch method in the Siebel eScript ?

Example:

If the Siebel Administration logs into Siebel application and click on the Contact Screen. It should only show the contacts who’s contact method is E-mail.

For this requirement we can use SetNamedSearch method in Business Component script.

Note:  This requirement is only for [Visible Contact List View].

  1. Login into Siebel Tools with SADMIN/SADMIN connecting for Sample database.
  2. Click on the Business Component in the Object Explorer.
  3. Query for a Contact Business Component and Lock the project.
    1. Use [ Alt + L ] to lock the project.
  4. Right click on the Business Component and Click on the Edit Server Script.
  5. Locate the following method. [BusComp_PreQuery ]
  6. Now write the following script to implement this requirement.

function BusComp_PreQuery ()
{
        TheApplication().TraceOn("D:\Setname.txt","Allocation","All");
       
        if(TheApplication().GetProfileAttr("Position") == "Siebel Administrator")
        {
                        TheApplication().Trace("Inside f Block");
                        this.SetNamedSearch("EmailContacts" , "[Preferred Communications] = 'E-Mail'")
        }
        TheApplication().Trace("View Name : " + sActiveViewName);
        TheApplication().Trace("Position Name : " + TheApplication().GetProfileAttr("Position") );
       
        TheApplication().TraceOff();
        return (ContinueOperation);
}


Explanation:
This.SetNamedSearch(ExprName, “[fieldname] optr ‘value’ ”);

  1. Compile the BC and Test.

Feb 7, 2012

How to invoke a Siebel Business Service

Business Service (BS): Is a place where you write to code to implement business rules and process.
We can also write the code at Bus Comp and Applet level but that makes our code and business logic to be
           • Distributed
           • Difficult to manage
           • Cannot be reused
Siebel Business service has a slight more overhead than the code at Applet or Bus Comp level but it helps us to make our code
            • Centralized
            • Easier to manage
            • Can be reused
So general rule of thumb to select where to write the code is
If same business rules are applicable on more than one entity then we write a generalized code at BS level.
You can create business services in
Siebel Tools: Code change is SRF dependent.
Siebel Client: Code change is SRF independent.
You can read more on both kinds of business services in the following post.
We can invoke a business Service through
1.    Runtime Events
2.    eScript
3.    User Property
4.    Runtime Events

To call a business service through runtime events
Enter the following information in the Action Set that you are creating
Business Service: Business Service Name
Business Service Method: Method Name
Business Service Context: “Input Argument”, “Value”
And based on the Event that you choose this business service will be invoked


• eScript
You can use the following Code to invoke a business service from escript
var svc = TheApplication().GetService(“BS Name”);
var Input = TheApplication().NewPropertySet();
var Output = TheApplication().NewPropertySet();
Input.SetProperty(“Type”,this.GetFieldValue(“Status”)); // Input Agruments
svc.InvokeMethod(“BSMethod”, Input, Output);


•    User Property
You can use named method property to invoke a business service from BC but this method is rarely used as it including complex conditions in the User property might not be possible. But it can come quite handy if you just want to invoke BS based on simple conditions

Name: Named Method 1
Value: “New Record”, “INVOKESVC”, “BS Name”, “BS Method”, “‘Input Agrument’”, “Value”, “‘Input Argument 2’”, “Value”

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);


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

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...