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

February 14, 2020

How to create cookies from server side?

Yes, you read it correctly, you can create cookies in the browser from the server side, and get your browser script to access them. This is enabled via Web Engine HTTP TXN business service.
Siebel Cookies
Siebel Cookies

var oBS = TheApplication().GetService("Web Engine HTTP TXN");

var Inputs = TheApplication().NewPropertySet();
var Outputs = TheApplication().NewPropertySet();

var psCookie = TheApplication().NewPropertySet();
psCookie.SetType("Cookie");
psCookie.SetValue("Value of Cookie");
psCookie.SetProperty "Path", "/";
Inputs.AddChild(psCookie);

oBS.InvokeMethod("SetResponseCookies", Inputs, Outputs);

Keep in mind that this method can be called from any other event in Siebel except application start(Application_Start) event due to product limitation .

Not just that one can use this service to get IP address of the client which is used to access Siebel. I will highly recommend to go through all the methods of Web Engine HTTP TXN business service in your free time.

How caching work in Siebel?

In any online transaction processing system like CRM most of the processing time is taken in finding the right record in database. No matter what database optimization technique you implement, your db processing time would be the highest among the time spent in web server and application server.
Siebel Database

February 09, 2020

How to update bulk records in Siebel using eScript?

The best suggestion anyone can give to update records in bulk in Siebel is to use Siebel EIM. However sometimes developers don't have time to create EIM job, test it in lower environments and get it working in some days, and business can't wait for that long, And pesky admin team won't give developers the SQL access to production.



Then this is the last solution. Write a dirty little script and run it in business service simulator.

February 28, 2016

Dynamically change start-up view for group of users

Requirement: To have a different start-up view for certain group of users in application.

Siebel sets start-up view of all the users using Application property which is a static view and the only way default view can be changed is by end user by updating user preferences. 

Solution: To make the view dynamic and override the user preferences following script can be added to Application_Start event of Application to redirect all the users to a specific view based on their responsibility.  These views can be used to show statuary information or terms and conditions.

Script queries Employee BC for logged in user and search for specific responsibility and executes a go to view if specific responsibility is found. Similar script can be used to change other part of the application. Feel free to share in comments below if you have come across similar behavior in your implementation.

var EmployeeBO = TheApplication().GetBusObject("Employee");
var EmployeeBC = EmployeeBO.GetBusComp("Employee");
var userResp;
with (EmployeeBC)
{
ActivateField("Login Name");
ActivateField("Responsibility");
var UserName = TheApplication().LoginName();
SetSearchSpec("Login Name", TheApplication().LoginName());
ExecuteQuery(ForwardOnly);
if(FirstRecord()){
userResp = GetFieldValue("Responsibility");
}
return (CancelOperation);
}
if( userResp == ""){
{
TheApplication().GotoView("");
}else{
return (ContinueOperation);
}


Hope it helps

January 16, 2016

How to get name of siebel server in eScript?

I found this script recently on support web which allows us to get value of Siebel server name, log directory of the current session. I quickly extended script to get value of siebel task id and process id to help me in my debugging.

These values can be very useful if you are working on multi server issue. With the help of task Id I was able to find the log of current session without opening each log file. Please share in comments below on how you choose to use this script.

var serverSession_BO = TheApplication().GetBusObject("Server Admin - Sessions");
var serverSession_BC = serverSession_BO.GetBusComp("SA-VBC Session");
var taskParam_BC = serverSession_BO.GetBusComp("Server Task Parameter");

serverSession_BC.ClearToQuery();
serverSession_BC.SetSearchSpec("OM_LOGIN", logInName);
serverSession_BC.ExecuteQuery(1);
serverSession_BC.FirstRecord();

taskParam_BC.ClearToQuery();
taskParam_BC.SetSearchSpec("Parameter", "Log directory");
taskParam_BC.ExecuteQuery(1);
taskParam_BC.FirstRecord();


var compName = serverSession_BC.GetFieldValue("CC_ALIAS");
var siebsrvrName = serverSession_BC.GetFieldValue("SV_NAME");
var task_id = serverSession_BC.GetFieldValue("TK_TASKID");
var p_id = serverSession_BC.GetFieldValue("TK_PID");
var logDir = taskParam_BC.GetFieldValue("Current Value");


Additionally one can also find the windows process id and thread id by using following script.

var processId, taskId;
processId = taskId = ""; // initialize to satisfy eScript parser

//evaluate to suppress STDCALL not being recognized with eScript parser
eval('processId = SElib.dynamicLink("kernel32.dll","GetCurrentProcessId", STDCALL)');
eval('taskId = SElib.dynamicLink("kernel32.dll","GetCurrentThreadId", STDCALL)');

processId = processId.toString();
taskId = taskId.toString();

I bet you wont be able to do this in any cloud application. :)

Hope it helps. 

September 19, 2015

Siebel PropertySet Demistyfied [Infogrpahic]

This is my first post in response to analysis of Google Analytics search reports. In this series I will look at search terms searched by Siebel developers on Google and try to answer them with infographics.

Recently someone landed on How to Siebel? by searching keywords on Google: "Difference between GetValue() and GetProperty()"

There is ample information available on property set methods in bookshelf. Here is my answer using infograph.
Siebel Property Set Methods


GetValue() method returns the value of the property set, in example above  output will be : "My Value"

GetProperty() method returns the value of the specific property, in above example GetProperty("Weight") will return "1500"

If you looking for advanced property set concepts and traversing methods, then I will recommend going through How to traverse property set @ SiebelUnleashed

To receive more articles like this please subscribe via email by submitting form below.

July 18, 2015

How to pass arguments by reference in Siebel?

Yes! it is possible to pass arguments by reference to Siebel functions. This technique is not documented in bookshelf and most of developer use this unknowingly while passing true or false to CanInvoke property in WebApplet_PreCanInvokeMethod Event of applets to make controls active or inactive.

Lets see how it works.

Nothing special needs to be done by calling function, only change made is in callee function in declaration of arguments by prefixing & ampersand just like &CanInvoke in PreCanInvokeMethod.


 Lets see an example :

function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if(MethodName == "PassByReferenceTest")
{
var privatePS = TheApplication().NewPropertySet();
privatePS.SetProperty("test","something");
subFunction(privatePS);
TheApplication().RaiseErrorText(privatePS.GetProperty("test"));
return(CancelOperation);
}
return (ContinueOperation);
}

function subFunction (&parameter)
{
parameter.SetProperty("test","TestSuccesful");
}


Above script declares a new property set and sets value of a process property to a string("something"), which is over written("TestSucccesful") by subFunction by directly accessing it through the memory pointer.  When business service is executed RaiseErrorText whill print "TestSuccesful" instead of "something".

 
This trick will potentially save you memory allocation and speed up you code a bit. Please be mindful that this code is just an experiment and should not be used in production environment without proper testing.


Happy coding :)

July 02, 2015

Not all control paths lead to a return statement. (SBL-SCR-00128)

Not all control paths lead to a return statement. (SBL-SCR-00128)

  This issue was fixed in version 8.1.1.7, but has been reported re-occurring in IP2014 patchset 3, it is caused due to product defect. This can cause interruptions in full compile of srf.

While compiling srf, if any script which has try catch block which has return statement in try block and does not have return statement outside catch, then this error will interrupt the srf compilation. 


To resolve this disable the "Deduce Types" scripting option in Siebel Tools as shown below.

March 18, 2015

Siebel Interview Questions : Scripting

See collection of Date functions in Siebel eScript

Siebel Scripting is one the most interesting areas of Siebel, if it is done properly it can do wonders for business, otherwise it can lead to ever increasing technical debt.

Siebel Tools Scripting IDE

Before jumping to questions let us look at some lessor known facts of Siebel Scripting:
  1. Siebel support two scripting languages: eScript and VBScript
  2. Full name of eScript is ECMA script which developed further to become javascript. 
  3. Garbage collection of Siebel scripts in not automatic
  4. Siebel eScript does support prototype overriding and classes
  5. Siebel eScript can pass arguments by value and pass by reference

Question: Which Siebel objects supports scripting?

Answer: Script can be written on following objects in Siebel:
  1. Business Services
  2. Client Side Business Services
  3. Business Components
  4. Applets
  5. Application
  6. Product Configurator Events
  7. Smart Scripts
  8. Workflows (via business services)
  9. Open UI js class files
  10. Browser scripts on Applets, BusComps, Application, Business Services
  11. Siebel Webtemplates SWTs
  12. ?????

Question : How to change primary record of MVG using scripting?

Answer: Primary record of MVG can be changed by setting the SSA Primary Field of the associated record. 

Script could look like:  
        bcOpty.ClearToQuery();
        bcOpty.ExecuteQuery();
        if(bcOpty.FirstRecord())
        {
            var bcMVG = bcOpty.GetMVGBusComp("MVF Name");
           bcMVG.ActivateField("SSA Primary Field");
            bcMVG.ClearToQuery();
            bcMVG.SetViewMode(AllView);
            bcMVG.SetSearchSpec("Id", "1-12345");
            bcMVG.ExecuteQuery();
             if(bcMVG.FirstRecord())
            {
               bcMVG.SetFieldValue("SSA Primary Field", "Y");
               bcOpty.WriteRecord();
            }
        }

Question : How to set pick list field using script?

Answer:  GetPicklistBusComp() Pick() methods are available in eScript by which system can search on pick list buscomp and pick desired record.

Syntax for pick method can look like:
oPickBusComp = buscomp.GetPickListBusComp("FieldName");
oPickBusComp.ClearToQuery();
oPickBusComp.SetSearchSpec("Id","12345");
oPickBusComp.ExecuteQuery();
oPickBusComp.Pick();
buscomp.WriteRecord();

Question : How to show a confirmation(Ok/Cancel) dialogue box in Siebel?

Answer: Confirmation Dialog box should be implemented through browser script using javascript confirm method. This method prompts users with option to proceed or cancel the process.



Click here for example.



Question : How to call batch file through scripting?

Answer: Siebel provides C libraries to access the host of Siebel server.
Clib.system() is one of those functions which allows script to pass some instructions to command processor of server host.
Using this method, a batch file can be invoked from Siebel which can do OS level changes.
Following instruction can execute Siebel.bat file on the server:

Clib.system("C:\\Scripts\\Batch\\Siebel.bat");

Question : How to update read only fields in Siebel?

Answer: Fields in Siebel are configured as read-only using "Field Read Only Field" and "BC Read Only Field" user properties. These user properties does not work on views where admin mode flag is set to Y.

BusComp.InvokeMethod("SetAdminMode", flag)

Question: What is the difference between SetAdminMode and SetViewMode(AllView)?

Answer :
  • SetAdminMode mimics the behaviour of Admin Views, and is used to update read only fields
  • SetViewMode instruction changes the default view mode of the business component, it used to access records which are not visible with default view mode.


Question : Is it possible to invoke workflow through browser script?

Answer: Workflow can be invoked through browser script if "Workflow Process Manager" declared as Client side business service in Application's User Property. 


Question : What type of error handling is available in Siebel eScript?

Answer: try catch finally instructions helps to handle run time errors in e-script.

  • try block marks the code which needs to handled
  • catch block declares commands which should be executed in case of error,
  • finally block is executed after try and catch has completed executing.

try
{
   statement_block
}
catch
{
   exception_handling_block
   [throw exception]
}
finally
{
   statement_block_2
}

Finally block is always executed no matter if there was error encountered or not.

Question: How to get language of Object Manager?

var lang = TheApplication().InvokeMethod("LANGUAGE");

Question :  What is difference between ActiveBusObject() and GetBusObject() methods?

Answer: ActiveBusObject is mostly used in UI based scripting requirements, this method can only return the handle of current BO instance.

For example: In Accounts screen ActiveBusObject will return Account BO and subsequent .GetBusComp().GetFieldValue will return the information from the record selected by user.

Same script in Contact Screen will return the Contact BO.

Important Points about ActiveBusObject: 
- It is not recomended to use ClearToQuery and ExecuteQuery on BC of ActiveBusObject as UI context for user will get lost.
- ActiveBusObject is the only way to get BO in browser script.

GetBusObject method should be used when current BO instance does not have the BC of interest. We can get handle of any BO in application using GetBusObject This is mostly used in background processes and workflows.