Este Siebel eScript permite cargar Listas de Valores desde un archivo plano codificado en UTF-8 como la siguiente muestra
PAISES;AFGHANISTAN;AFGHANISTAN;;AF;ESN;;1;Y;Y;;;;;;AFGHANISTAN
PAISES;ALAND ISLANDS;ALAND ISLANDS;;AX;ESN;;2;Y;Y;;;;;;ALAND ISLANDS
PAISES;ALBANIA;ALBANIA;;AL;ESN;;3;Y;Y;;;;;;ALBANIA
PAISES;ALGERIA;ALGERIA;;DZ;ESN;;4;Y;Y;;;;;;ALGERIA
PAISES;AMERICAN SAMOA;AMERICAN SAMOA;;AS;ESN;;5;Y;Y;;;;;;AMERICAN SAMOA
PAISES;ANDORRA;ANDORRA;;AD;ESN;;6;Y;Y;;;;;;ANDORRA
PAISES;ANGOLA;ANGOLA;;AO;ESN;;7;Y;Y;;;;;;ANGOLA
PAISES;ANGUILLA;ANGUILLA;;AI;ESN;;8;Y;Y;;;;;;ANGUILLA
PAISES;ANTARCTICA;ANTARCTICA;;AQ;ESN;;9;Y;Y;;;;;;ANTARCTICA
PAISES;ANTIGUA AND BARBUDA;ANTIGUA AND BARBUDA;;AG;ESN;;10;Y;Y;;;;;;ANTIGUA AND BARBUDA
El script:
function Service_PreInvokeMethod (MethodName, Inputs, Outputs){
switch(MethodName){
case "Importa_LOVs":
/*Importa Listas de Valores*/
Importa_LOVs(Inputs,Outputs);
return (CancelOperation);
break;
case "Borra_LOVs":
/*Elimina Listas de Valores*/
Borra_LOVs(Inputs,Outputs);
return (CancelOperation);
break;
}
return (ContinueOperation);
}
function Importa_LOVs(Inputs, Outputs){
var cmdArray, TypeArray, i, line, Cuenta, ContadorPublico, tamanio, encontrado;
var strType = "";
var strValor = "";
var strLIC = "";
var strBajo = "";
var strIdioma = "";
var strParLIC = "";
var strOrden = "";
var strDesc = "";
var LOVBO, LOVBC, LangBC, ParBC, sSpec;
try{
var fp = Clib.fopen("D:\\LOVS.CSV", "rt");
if ( fp == null ){
TheApplication().RaiseErrorText("\aError abriendo archivo para lectura.\n")
}else{
LOVBO = TheApplication().GetBusObject("List Of Values");
LOVBC = LOVBO.GetBusComp("List Of Values");
LOVBC.InvokeMethod("SetAdminMode", "TRUE");
ContadorPublico = 0;
TypeArray = new Array("LOV_TYPE");
while (null != (line=Clib.fgets(fp))){
cmdArray = line.split(";");
strType=cmdArray[0].substring(0,30);
strValor=cmdArray[1].substring(0,30);
strLIC=cmdArray[2].substring(0,50);
strBajo=cmdArray[4];
strIdioma=cmdArray[5];
strParLIC=cmdArray[6].substring(0,50);
strOrden=cmdArray[7];
strDesc = cmdArray[15].substring(0,255);
ContadorPublico=ContadorPublico + 1;
tamanio=TypeArray.length-1;
encontrado=false;
for(i=0;i<tamanio;i++){
if(TypeArray[i]=="strType"){
encontrado=true;
break;
}
}
if(!encontrado){
LOVBC.SetViewMode(AllView);
LOVBC.ClearToQuery();
sSpec = "[Type]='LOV_TYPE' AND [Name]=" +
String.fromCharCode(34) +
strType + String.fromCharCode(34) +
" AND [Language]='" +
strIdioma + "'";
LOVBC.SetSearchExpr(sSpec);
LOVBC.ExecuteQuery(ForwardOnly);
Cuenta = LOVBC.CountRecords();
if(Cuenta==0){
TypeArray.push(strType);
LOVBC.NewRecord(NewAfter);
LOVBC.SetFieldValue("Type","LOV_TYPE");
LOVBC.SetFieldValue("Value",strType);
LOVBC.SetFieldValue("Name",strType);
LOVBC.SetFieldValue("Description",strType);
LangBC=LOVBC.GetPicklistBusComp("Language Name");
LangBC.ClearToQuery();
sSpec="[Language Code]='" + strIdioma + "'";
LangBC.SetSearchExpr(sSpec);
LangBC.ExecuteQuery(ForwardOnly);
Cuenta = LangBC.CountRecords();
if(Cuenta>0){
LangBC.FirstRecord();
LangBC.Pick();
}
LOVBC.SetFieldValue("Translate","Y");
LOVBC.SetFieldValue("Multilingual","Y");
LOVBC.WriteRecord();
}
}
LOVBC.SetViewMode(AllView);
LOVBC.ClearToQuery();
sSpec = "[Type]='" + strType +
"' AND [Name]=" + String.fromCharCode(34) +
strLIC +
String.fromCharCode(34) +
" AND [Language]='"
strIdioma + "'";
LOVBC.SetSearchExpr(sSpec);
LOVBC.ExecuteQuery(ForwardOnly);
Cuenta = LOVBC.CountRecords();
if(Cuenta==0){
LOVBC.NewRecord(NewAfter);
LOVBC.SetFieldValue("Type",strType);
LOVBC.SetFieldValue("Value",strValor);
LOVBC.SetFieldValue("Name",strLIC);
LOVBC.SetFieldValue("Description",strDesc);
LangBC=LOVBC.GetPicklistBusComp("Language Name");
LangBC.ClearToQuery();
sSpec="[Language Code]='" + strIdioma + "'";
LangBC.SetSearchExpr(sSpec);
LangBC.ExecuteQuery(ForwardOnly);
Cuenta = LangBC.CountRecords();
if(Cuenta>0){
LangBC.FirstRecord();
LangBC.Pick();
//LOVBC.SetFieldValue("Language Name","Medio");
}
if(strParLIC!=""){
ParBC=LOVBC.GetPicklistBusComp("Parent");
ParBC.ClearToQuery();
sSpec="[Value]='" + strParLIC + "'";
ParBC.SetSearchExpr(sSpec);
ParBC.ExecuteQuery(ForwardOnly);
if(ParBC.FirstRecord()){
ParBC.Pick();
}
//LOVBC.SetFieldValue("Parent Id","Medio");//??
}
LOVBC.SetFieldValue("Low",strBajo);
LOVBC.SetFieldValue("Order By",strOrden);
LOVBC.SetFieldValue("Translate","Y");
LOVBC.SetFieldValue("Multilingual","Y");
LOVBC.WriteRecord();
}
}
}
}catch(e){
var fperr = Clib.fopen("D:\\ERRORES.log", "a");
var theDay="";
var strSysDate = new Date();
Clib.sprintf(theDay,"%02i",strSysDate.getDate())
var strStringDate = strSysDate.getFullYear()
+ "-"
+ strSysDate.getMonth()
+ "-" + theDay
+ " " + strSysDate.getHours()
+ ":" + strSysDate.getMinutes()
+ ":" + strSysDate.getSeconds();
Clib.fprintf(fperr, strStringDate + "\n");
sSpec = e.errText;
Clib.fprintf(fperr, sSpec + "\n");
Clib.fprintf(fperr, "Type:" + strType + "\n");
Clib.fprintf(fperr, "Value:" + strValor + "\n");
Clib.fprintf(fperr, "Name:" + strLIC + "\n");
Clib.fprintf(fperr, "Language Code:" + strIdioma + "\n");
Clib.fprintf(fperr, "Parent:" + strParLIC + "\n");
Clib.fprintf(fperr, "Low:" + strBajo + "\n");
Clib.fprintf(fperr, "Order By:" + strOrden + "\n\n");
Clib.fclose(fperr);
}finally{
Clib.fclose(fp);
LOVBO=null;
LOVBC=null;
LangBC=null;
ParBC=null;
cmdArray=null;
line=null;
strSysDate=null;
}
}
function Borra_LOVs(Inputs,Outputs){
var cmdArray, i, line, Cuenta, ContadorPublico;
var strType = "";
var LOVBO,LOVBC,LangBC,ParBC,sSpec;
try{
var fp = Clib.fopen("D:\\PROYECTOS\\LOVS.CSV", "rt");
if ( fp == null ){
TheApplication().RaiseErrorText("\aError abriendo archivo para lectura.\n")
}else{
LOVBO = TheApplication().GetBusObject("List Of Values");
LOVBC = LOVBO.GetBusComp("List Of Values");
LOVBC.InvokeMethod("SetAdminMode", "TRUE");
ContadorPublico = 0;
while (null != (line=Clib.fgets(fp))){
cmdArray = line.split(";");
strType=cmdArray[0].substring(0,30);
ContadorPublico=ContadorPublico + 1;
LOVBC.SetViewMode(AllView);
LOVBC.ClearToQuery();
sSpec = "[Type]='" + strType + "'";
LOVBC.SetSearchExpr(sSpec);
LOVBC.ExecuteQuery();
Cuenta = LOVBC.CountRecords();
sSpec="";
if(Cuenta>0){
while(LOVBC.LastRecord()){
sSpec = LOVBC.GetFieldValue("Id");
LOVBC.DeleteRecord();
}
}
}
}
}catch(e){
var fperr = Clib.fopen("D:\\ERRORES.log", "a");
var theDay="";
var strSysDate = new Date();
Clib.sprintf(theDay,"%02i",strSysDate.getDate())
var strStringDate = strSysDate.getFullYear()
+ "-"
+ strSysDate.getMonth()
+ "-" + theDay
+ " " + strSysDate.getHours()
+ ":" + strSysDate.getMinutes()
+ ":" + strSysDate.getSeconds();
Clib.fprintf(fperr,strStringDate + "\n");
sSpec = "Error borrando Listas de Valores"+e.errText+"\n"+(sSpec!=""?"RowId:"+sSpec:"");
Clib.fprintf(fperr, sSpec + "\n");
Clib.fprintf(fperr, "Type:"+strType+ "\n");
Clib.fclose(fperr);
}finally{
Clib.fclose(fp);
LOVBO=null;
LOVBC=null;
LangBC=null;
ParBC=null;
cmdArray=null;
line=null;
strSysDate=null;
}
}