Thursday 12 May 2022

Siebel GoTo View - Handling Realtime cases

 Hello All, 


We all must have used GoTo view functionality of siebel to navigate to a particular view from current view.

What if the requirement is to get to a particular record on a record? Well this cannot be directly achieved via GoTo View as we cannot pass Id there.

But this can be achieved if we pass the context BO in GoTo View, i.e. The syntax is TheApplication().GoToView("ViewName","BO"), we need to set the record context in BO then pass the BO.

Algo:

1.Take the RowId of the record we want to navigate to 

2. Query the record to set the context

3. Pass the BO Variable with GoTo View, to see the magic happen :-)


Sample Script:

 if(MethodName == "Navigate")
 {
 var sB0 = TheApplication().GetBusObject("Auto Vehicle")
 var gBc = sB0.GetBusComp("Auto Vehicle");
 var assetId = this.BusComp().GetFieldValue("Asset Id"); //Id for the record we want to navigate

 with(gBc)  //Set the context by querying the record
     {
     ClearToQuery();
     SetViewMode(AllView);
     SetSearchSpec("Id",assetId);
     ExecuteQuery(ForwardOnly);
     }
 TheApplication().GotoView("Auto Vehicle Service Request View",sB0);    //call goto view with BO context
   return(CancelOperation);
 }
//end method

Simple yet very useful, your comments and suggestion are always welcome.

Monday 4 April 2022

Working with Attachments in Siebel - Part3 Putting TypeRestriction

 Hello All, 

In this post let us try to put restriction on the Type of files while adding new Attachments.

The Logic is pretty simple, 

1. Identify the Target Attachment BC

2. Identify the File Type Field

3. Write Script on PreWriteRecord of Business Component

In any attachment applet, we can see the Fields Name, Size (in Bytes) ,Type etc.


 



Lets Try to write a Piece of Code to fetch the Type of File:

The code below prevent to attach exe, msi or apk files that can be cause potential threats to system 

function BusComp_PreWriteRecord ()

{

var ext= GetFieldValue("FileExt"); //Get the File Extension

switch(ext) {

  case "exe":  

TheApplication().RaiseErrorText("This Type of File is Not Allowed");                    

break;

  case "EXE":

TheApplication().RaiseErrorText("This Type of File is Not Allowed");

break;

  case "msi":

TheApplication().RaiseErrorText("This Type of File is Not Allowed");

break;

  case "apk":

TheApplication().RaiseErrorText("This Type of File is Not Allowed");

break;

  case "APK":

TheApplication().RaiseErrorText("This Type of File is Not Allowed");

break;

  default:

//do nothing 

}

}




Error Popup on Save Record:









This way we can keep our file system clean from any virus, unwanted apps etc..
Smart way to secure application :-) 


Previous Post                        Next Post

Friday 1 April 2022

Working with Attachments in Siebel - Part2 Putting Size Restriction

 Hello All, 

In this post let us try to put size restriction while adding new Attachments.

The Logic is pretty simple, 

1. Identify the Target Attachment BC

2. Identify the File Size Field

3. Write Script on PreWriteRecord of Business Component

In any attachment applet, we can see the Fields Name, Size (in Bytes) ,Type etc.


 



Lets Try to write a Piece of Code to fetch the Size:

function BusComp_PreWriteRecord ()

{

    this.ActivateField("FileSize");

    var size= this.GetFieldValue("FileSize"); //Field that has size

    var sizeMB = size/1000000 ; //converting Bytes to MB

if (ToNumber(sizeMB) >= 5 ) //checking the size to less then 5 MB

{

TheApplication().RaiseErrorText("Please add file less then 5 MB");                     

}

}


Error Popup on Save Record:









very simple effective solution to Keep Siebel File System under control :-) ,any suggestions are always welcome.


Previous Post                        Next Post

Tuesday 29 March 2022

Working with Attachments in Siebel - Part1 Calculating Size

 Hello All, 

Siebel Attachment's are very useful functionality to attach documents, files ,images etc. with parent records.

There are certain consideration with attachment that comes into picture one day or the other.

1. Size Restriction on Attachments

2. Type Restriction on Attachments

3. Size control for Siebel File System

4. FS Cleanup to clear orphan Attachments

lets cover these one by one, 

before starting let us first check the total size of attachments under a particular entity, (Service Request in my case)

Client Side BS to get the Size of attachment

function Service_PreInvokeMethod (MethodName, Inputs, Outputs)

{

try

 {    

  if(MethodName == "DeleteAttachment")

  {

   var vSRBO = TheApplication().GetBusObject("Service Request (eService)");

   var vSRBC = vSRBO.GetBusComp("Service Request (eService)");

   var vSRBCAtt = vSRBO.GetBusComp("Service Request Attachment");

   var fileSize ="0",filebyte="0";

   with(vSRBC)

      {

      ActivateField("Id");

      ClearToQuery();

      SetViewMode(AllView);  

      var varSpec = "[Created] >= '1/1/2020' AND [Created] <= '1/1/2022'";

      SetSearchExpr(varSpec);

  ExecuteQuery(); 

      var vFirstRec = FirstRecord();

  while(vFirstRec)

   {

with(vSRBCAtt)

{

ActivateField("ActivityFileName");

ActivateField("ActivityFileSize");

ClearToQuery();

SetViewMode(AllView);  

ExecuteQuery(); 

var FirstRec = FirstRecord();

  while(FirstRec)

  {    

  var filename = GetFieldValue("ActivityFileName"); 

  filebyte = GetFieldValue("ActivityFileSize");

  fileSize = ToNumber(fileSize)+ToNumber(filebyte);

  FirstRec = NextRecord();

  }  

}     

   vFirstRec = NextRecord();

 

   }  

TheApplication().RaiseErrorText("TotalSize: "+fileSize);

   }  

   return(CancelOperation);

  }

 }//End Try

 catch(e)

 {

 // return(CancelOperation);

  if (typeof e.errText == "undefined")

  TheApplication().RaiseErrorText(e.toString());

  else

  TheApplication().RaiseErrorText(e.errText + "\n" + e.toString());

 }

 finally

 {

   vSRBO = null;

   vSRBC = null;

 }

}


the output will be in bytes , we can convert to MegaBytes by dividing by 1024, or GigaBytes by dividing 1024*1024

As Highlighted by Alex Sir , it will be divide by 1,000,000 not 1024 to convert to Mega Bytes

here, 10306580 if Divided by 1024*1024 gives 9.82 GB








We will continue with Putting restriction on file attachments in next post.

Sunday 27 March 2022

Application Level Functions in Siebel - LookupDesc

 Hello All,

There have been certain requirement that makes us write repetitive code, like sending email or SMS where we need to write either a function or script each time we need to call the code. Can there be some better way of handling this type of repetitive code? 

Application Level functions are the solution to these type of requirement. Consider one more case we use LookupValue functions to fetch LOV value that gives us either Name or Display Value. In case when length is more then 30 we need to call custom code.

Here we can make a Application level function say LookupDesc that returns Description and can be call by TheApplication() method.

See sample code for the same

//Your public declarations go here...
 function LookUpDesc(Type,Value)
{
 try
{
var sDesc = "";
var boLOV = TheApplication().GetBusObject("List Of Values");
var bcLOV = boLOV.GetBusComp("List Of Values");
with (bcLOV)
{
ClearToQuery();
SetViewMode(AllView);
ActivateField("Description");
SetSearchSpec("Type", Type);
SetSearchSpec("Value", Value);
ExecuteQuery(ForwardOnly);
if (FirstRecord())
 {
sDesc = GetFieldValue("Description");
 }
}
//with
return(sDesc);
}
catch(e)
 {
 throw(e);
}
 finally
{
bcLOV = null;
boLOV = null;
} }

Add this function in Application:















You can use this with below Syntax:








try and explore the code reusability :-)

Wednesday 31 March 2021

Apex Triggers in Salesforce

 Hello All, 

Before we write any example let us first understand what are Triggers.

Just like database triggers that execute on/after/before certain event to execute a set of statements, Apex triggers also server the same purpose.

Triggers allows us to do custom actions on events, i.e. do some field setting, fire SOQL statement, execute some complex equation,

supported events ,

  • before insert
  • before update
  • before delete
  • after insert
  • after update
  • after delete
  • after undelete

sample Trigger syntax,

trigger TriggerName on ObjectName (trigger_events) {                  

//code here 

}


TriggerName is unique Name for Trigger, Object Name is Entity Name,

Note : in the below example we are using Context to get the current record details,
for(Opportunity opp : Trigger.New)

e.g.

1. set a Field value when a Opportunity record is updated

trigger SetBuyingTimeFrame on Opportunity (before update) {
for(Opportunity opp : Trigger.New)
{
opp.Buying_Time_Frame__c = '1-Immediate';
}
}

2. Using a If Else condition in trigger

trigger SetBuyingTimeFrame on Opportunity (before update) {
for(Opportunity opp : Trigger.New)
{
if(opp.Enquiry_Classification__c=='1-Excellent')
{
opp.Buying_Time_Frame__c = '1-Immediate';
}
else 
{
opp.Buying_Time_Frame__c = '5-Within 3 Months';
}
}
}

2. Using a switch statement in trigger

ttrigger SetBuyingTimeFrame on Opportunity (before update) {
for(Opportunity opp : Trigger.New)
{
switch on opp.Enquiry_Classification__c{
when '1-Excellent' {opp.Buying_Time_Frame__c = '1-Immediate';}
when '2-Very High' {opp.Buying_Time_Frame__c = '2-Within 1 Week';}
when '3-High' {opp.Buying_Time_Frame__c = '3-Within 2 Weeks';}
when else {opp.Buying_Time_Frame__c = '5-Within 3 Months';}
}
}
}

the examples are endless :-), more details are available on link, 

Creating a Lookup Relation in Salesforce

 Hello All, 

Many times we require data from other entity being stored and referenced in source entity. i.e. Account Details in Opportunity.

We have Lookup relationship type for implementing the requirement, so lookup defines a way to get fields data from some Target entity to the source Entity

let see a simple scenario, we require to bring Financer to Opportunity (Financer is a type of Account with Type having value Technology Partner)

1. Setup- Objects - Fields ,click New

Select Lookup Relationship






2. Select the Target Entity, Since i need to fetch account details i will choose Account.








3. Provide Field Label and Description, 

there are Option to make the Fields Required, by Ticking the Required Flag

and option for deleting the Relationship (clear the value or do not delete)  








4. Now Comes the Important part, setting the Filter Criteria

As mentioned in the beginning, i need to show Account in the Lookup, that have Type as Technology Partner.

Select the field in Account on which we need to Filter 

Account:Type ,and in value choose Technology Partner from the Popup List.














Now when we see the Financer in the Form , we see only Records that match the Filter Criteria specified. Save and add field on the layout. 











I will be covering some more complex scenarios in upcoming posts.


Siebel GoTo View - Handling Realtime cases

 Hello All,  We all must have used GoTo view functionality of siebel to navigate to a particular view from current view. What if the require...