Friday, October 28, 2016

Bulk Upload on Button Click


Server Script on Applet to upload excel sheet:-
function WebApplet_PreInvokeMethod (MethodName)
{
if (MethodName == "UploadFile")
{
var i =2;
var ExcelApp = COMCreateObject("Excel.Application");
ExcelApp.Workbooks.Open("D:\\UploadFile.xlsx");
ExcelApp.Visible = false;
var oBOLdVal = TheApplication().GetBusObject("Service Request");
var oBCLdVal = oBOLdVal.GetBusComp("Service Request");

while(ExcelApp.ActiveSheet.Cells(i,1).Value!= 'undefined')
{
var Type = ExcelApp.ActiveSheet.Cells(i,1).Value;
var SubType = ExcelApp.ActiveSheet.Cells(i,2).Value;
var Description = ExcelApp.ActiveSheet.Cells(i,3).Value;
var Status = ExcelApp.ActiveSheet.Cells(i,4).Value;
//var Product = ExcelApp.ActiveSheet.Cells(i,5).Value; //You can define more cell here

with(oBCLdVal)
{
ActivateField("Service Request Type");
ActivateField("Lot Number");
ActivateField("Description");
ActivateField("Status");

ClearToQuery();
//ExecuteQuery();
InvokeMethod("SetAdminMode","TRUE");
NewRecord(NewAfter);
SetFieldValue("Service Request Type",Type);
SetFieldValue("Lot Number",SubType);
SetFieldValue("Description",Description);
SetFieldValue("Status",Status);
WriteRecord();

}
i=i+1;
}
ExcelApp.Quit();
ExcelApp = null;
oBOLdVal = null;
oBCLdVal = null;
TheApplication().RaiseErrorText("Load Success");
return(CancelOperation);
}
return(ContinueOperation);

No comments:

Post a Comment