We usually have a requirement where we get data in the CSV file and then we need to read to data from CSV file. Below is a code snippet that allows you to read from an attached CSV file in Siebel.

For this example I have taken Account Attachment BC but you can take any BC you want. Here is how it works.

  • You receive a CSV file.
  • You attach it to an attachment BC (Accounts in example below)
  • Read that file.
  • Do whatever you want to do with data.

Here is the code.

function ReadCSVFile ()
{
      var oBusObj = TheApplication().GetBusObject(”Account”);
      var oAccAttBC = oBusObj.GetBusComp(”Account Attachment”);
      var LVal;
      var cntr;
      cntr = 1;
      oAccAttBC.ActivateField(”AccntFileName”);
      oAccAttBC.ClearToQuery();
      oAccAttBC.SetViewMode(3);
      oAccAttBC.SetSearchSpec(”Id”,’1-4FBYH’); // Row Id of Attachment Record
      oAccAttBC.ExecuteQuery();
      if(oAccAttBC.FirstRecord())
         {
          var temppath = oAccAttBC.InvokeMethod(”GetFile”, “AccntFileName”);
          // because the path is returned as “Success,Path” so remove success
          var pos = temppath.indexOf(”,”); 
         var path = temppath.substring(pos+1);
         //path is without the status
          var oFile = Clib.fopen(path,”r”); 
          if( oFile == null )
          {  TheApplication().RaiseErrorText(path); }
          var string = (Clib.fgets(2000,oFile)); //usually the first line is hearder so ignore it
          while(!Clib.feof(oFile))
               {
                 string = (Clib.fgets(2000,oFile));
                 LVal = string.split(”,”);
                 //LVal is the now an array populated with data
                 //Now put your logic to do whatever you want to do with data
                 //for example
                
                 if(LVal[0] == “Test”)
                   {
                     //do something
                   }
                 cntr++; // just to count number of lines that have been processed
               }
         }
}

OkAvarageGoodVery GoodExcellent (2 votes, average: 3 out of 5)
Loading ... Loading ...

Related Posts