Creating a File in Epicor Function and Downloading in Kinetic Client
By Bryan Spencer
There have been several use cases where I needed to create a file and drop the file in a location so that a user can pick it up. In classic, this was straightforward since you had access to the code. In the Epicor Kinetic browser environment, this can be tricky.
Let’s get started.
The file must be created on the server side and then made available to download in the client. To do that I created a function where I build up the file contents in a string builder. The magic happens at the end where we use the File Transfer Service.
Let’s look a little closer at that statement.
The first parameter of the Upload method is essentially the location on the server specified as one of the special folders.
Second is the name of the file.
Finally, the contents are in a byte array. Take note that I send the name of the file back to the client via the output parameter.
CallService<Ice.Contracts.FileTransferSvcContract>(x=>
{
x.UploadFile(
Epicor.ServiceModel.Utilities.SpecialFolder.CompanyData,
$"{fname}-PP.dat",
Encoding.UTF8.GetBytes(fpart + sb.ToString())));
this.output = $"{fname}-PP.dat";
});
On the client side I created a button and connected to the click event.
Kinetic function widget is used to call the function that we created earlier. The key part of this event is the file-transfer-kinetic widget. The special folder must match the special folder that was used in the function. Server path is mapped to the returned filename.