Thursday 12 December 2013

Custom File Upload Applet Based On Class CSSSWEFRImpExp / CSSSWEFRImpExp Fails

We have an Import Button in an Applet, on clicking that button, a small popup applets comes and we can upload CSV which is to be imported in to parent applet. This functionality works well in HI mode. But this functionality fails in OpenUI.
Oracle support says this issues addressed in 8.1.1.11, but still I am getting error.

We can Implement this feature with some tricks.

lets create a button on applet and give method name as "FilePopup". And make sure that CanInvoke is true for this method.



function WebApplet_PreCanInvokeMethod (MethodName, &CanInvoke)
{
    if(MethodName == "FilePopup")
    {
            CanInvoke="TRUE";
            return (CancelOperation);
    }
    return (ContinueOperation);

Now open Applet Browser script. 


function Applet_PreInvokeMethod (name, inputPropSet)
{
    switch(name)
    {
        case "FilePopup":
        var ShowModalOptions= "dialogHeight:150px;dialogLeft:100px;dialogWidth:350px;scrollbars:no";
        var intRet = theApplication().ShowModalDialog ("FileImport.htm", "", ShowModalOptions);
       
        var Bc = this.BusComp();
        var csvval=intRet.split("|");
       
        for(var j=0;j<csvval.length-1;j++){
            this.InvokeMethod("NewRecord");
            var csvvalue=csvval[j].split(",");
            Bc.SetFieldValue("First Name",csvvalue[0]);
            Bc.SetFieldValue("Last Name",csvvalue[1]);
            Bc.SetFieldValue("Age",csvvalue[2]);
            Bc.SetFieldValue("Sex",csvvalue[3]);
        }

        return ("CancelOperation");
        break;

        default:
        return ("ContinueOperation");
        break;
    }
    return ("ContinueOperation");
}


Next step is creating an HTML file. Copy the below code and save it as  "FileImport.htm"
in Webserver as well as siebel server. ( \Client\PUBLIC\ and \siebsrvr\WEBMASTER\ )

<html>
</head>
<script language="javascript" src="23030/scripts/3rdParty/jquery.js"></script>
<script>
$(document).ready(function(){

$("#filename").change(function(e) {
var ext = $("#filename").val().split(".").pop().toLowerCase();

if($.inArray(ext, ["csv"]) == -1) {
alert('Upload CSV');
return false;
}

if (e.target.files != undefined) {
var reader = new FileReader();
reader.onload = function(e) {
var csvval=e.target.result.split("\n");
var inputrad="";
for(var j=1;j<csvval.length-1;j++){
    var csvvalue=csvval[j].split(",");
    for(var i=0;i<csvvalue.length;i++)
    {
    var temp=csvvalue[i];
    if(inputrad==""){
         inputrad=temp+"";
    }else if(i!==0){
         inputrad=inputrad+","+temp+"";
    }else{
        inputrad=inputrad+""+temp;
    }
   
   
    }
    inputrad =inputrad+"|";
}

window.returnValue = inputrad;
return inputrad;
};
reader.readAsText(e.target.files.item(0));

}


});
$("#import").click(function(){
    self.close();
});
})
</script>
</head>
<body>
<input type="file" name="filename" id="filename">
    <div id="csvimporthint_1">
        <table border="1" id="csvimporthint">
        </table>
    </div>
<input type="button" id="import" value="import">

</body>
</html>

compile applet and run GenB script.
Click on Import button and test this functionality.

No comments :

Post a Comment