Siebel Tools > Useful small scripts for Siebel Tools
How to read/write a csv file with escript
The file must be in UTF-8 format. This function can read the scv File
function ReadCSVFile(path) { var fileopen=Clib.fopen(path,"ru");
if (fileopen == null ) TheApplication().RaiseErrorText("Error opening file for reading.") else { var line=Clib.fgets(fileopen); var body=line; while ( null != (line=Clib.fgets(fileopen)) ) { body=body+line; } } Clib.fclose(fileopen);
return body; }
Syntax for Clib.fopen is Clib.fopen(filename, mode)
Options for mode are
Argument
|
Mode
|
Required
|
r
|
Opens the file for reading. The file must already exist.
|
Yes. You must include one of these arguments.
|
w
|
Opens the file for writing. If the file does not exist, then Siebel eScript creates the file.
|
a
|
Opens the file in append mode.
|
b
|
Opens the file in binary mode. If you do not specify b, then this method opens the file in text mode and performs an end-of-line translation.
|
No
|
t
|
Opens the file in text mode. For a non-ASCII character:
§ You use the u argument.
§ You do not use the t argument.
|
No
|
u
|
Opens the file in Unicode mode as UTF-16 or Little Endian. For example:
Clib.fopen("filename.txt", "rwu")
You can use the u mode for ASCII and non-ASCII characters.
|
No
|
From Oracle Bookshelf I found some more examples
The following example opens a file, writes a string to that file, and then uses the default codepage to read the string from this file:
var oFile = Clib.fopen("myfile","rw"); if (null != oFile) { var sHello = "Hello"; var nLen = sHello.length; Clib.fputs(sHello, oFile); Clib.rewind(oFile); Clib.fgets (nLen, sHello); }
Example 3 The following example opens a file, writes a string to this file, then uses Unicode to read the string from this file:
var oFile = Clib.fopen("myfile","rwu"); if (null != oFile) { var sHello = "Hello"; var nLen = sHello.length; Clib.fputs(sHello, oFile); Clib.rewind(oFile); Clib.fgets (nLen, sHello); }
Example 4 The following example specifies a file path:
function WebApplet_ShowControl (ControlName, Property, Mode, &HTML) { if (ControlName == "GotoUrl") { var fp = Clib.fopen("c:\\test.txt","wt+"); Clib.fputs("property = " + Property + "\n", fp); Clib.fputs("mode = " + Mode + "\n",fp); Clib.fputs("ORG HTML = " + HTML + "\n",fp); Clib.fclose(fp); HTML = "<td>New HTML code</td>"; } return(ContinueOperation);
How to get the value of an inactive field in a Business Component
This function can get the value
function GetInactiveFieldValue(id,fieldName) { var busObjSR,busCompSR; try { busObjSR=TheApplication().GetBusObject("Service Request"); busCompSR=busObjSR.GetBusComp("Service Request");
busCompSR.ClearToQuery(); busCompSR.SetViewMode(AllView); busCompSR.ActivateField(fieldName); busCompSR.SetSearchExpr("[Id]='"+id+"'"); busCompSR.ExecuteQuery(ForwardOnly); if(busCompSR.FirstRecord()){ return busCompSR.GetFieldValue(fieldName); } }finally{ // Clean busObjSR=null; busCompSR=null; } }
How to update/delete/process multiple fields in a Business Component
Delete multiple selection example
while (FirstSelected()) { InvokeMethod("DeleteRecord"); NextSelected(); }
do{
// Do something here
}while(NextSelected());
|