Tuesday, January 28, 2014

Siebel eScript – Business Service to Read Data from File


I guess we all have seen this kind of scenario where we had to read the data from flat file (.txt, .csv etc) in our Siebel career. If you have never worked on this kind of requirement then probably you will in near future. Any way knowledge never hurts so it’s good to share what we know…. J  

Today I am going to share a small but useful script. This script reads data from flat file and later you can use that data to perform Siebel operations as per your requirement. I am posting some part of code here which relates to this post, Error handling and all have not been included in this post but still you can browse this post “Siebel Scripting Tips” to get an idea on that.

if (MethodName=="ReadFileContent")
  {
        var source = Clib.fopen("D:\\SiebelCrmTip\\Test.txt", "rb");
        var buff  =  "", length = 0, sContent  =  "" ;
        while((length = Clib.fread(buff, 1, source)) != 0)
         {
          sContent = sContent + buff;
         }    
        Outputs.SetProperty("FileContent",sContent);
        Clib.fclose(source);
   return (CancelOperation);
  }



Your comments and suggestions are always welcome… Happy Siebeling… J



2 comments :

  1. Hi How Do I read file from Text File and Loop the .txt for new line.
    Example on .txt files :
    ABC
    DEF
    HIJ

    ReplyDelete
  2. Hello Wahyudi,

    Try Clib.fgets function this function takes /n itself and loops through the file each time taking /n as identifier.
    so for a file with
    ABC
    DEF
    HIJ

    it will run three time.

    Try this .

    while (null != (sLine = Clib.fgets(source))
    {
    a = a+sLine ;
    }

    output should be , ABCDEFHIJ

    ReplyDelete