In D365FO the file import utilities through the
methods of the WINAPI classes have been deprecated.
In this new version based on Cloud, we can use temporary URLS to help us
perform these loads.
An example of import is the following:
I worked from a RunBase class, in which I used its "Dialog" method to offer the user an interface in which to upload the file to be treated:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| class SPBImportFile extends RunBaseBatch
{
private DialogRunbase myDialog;
private DueDate dueDate;
private DialogField dialogDueDate;
private const str FileUploadName = 'FileUpload';
private const str OkButtonName = 'OkButton';
public Object dialog()
{
VendParameters vendParameters = VendParameters::find();
eMDdialog = new DialogRunbase("@SPBLabels:EMDImportation", this);
var dialogGroupParameters = myDialog.addGroup("Parametros");
dialogGroupParameters.columns(2);
dialogDueDate = myDialog.addFieldValue(extendedTypeStr(DueDate), dueDate);
var dialogGroup = myDialog.addGroup();
FormBuildControl formBuildControl = myDialog.formBuildDesign().control(dialogGroup.name());
FileUploadBuild dialogFileUpload = formBuildControl.addControlEx(classstr(FileUpload), FileUploadName);
dialogFileUpload.baseFileUploadStrategyClassName(classstr(FileUploadTemporaryStorageStrategy));
dialogFileUpload.fileNameLabel("@SYS308842");
return myDialog;
}
}
|
I used the 'DialogPostRun' method to manage the
controls and enable the accept button in the dialog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| public void dialogPostRun(DialogRunbase _dialog)
{
super(_dialog);
FileUpload fileUpload = this.getFormControl(_dialog, FileUploadName);
fileUpload.notifyUploadCompleted += eventhandler(this.uploadCompleted);
this.setDialogOkButtonEnabled(_dialog, false);
}
protected FormControl getFormControl(DialogRunbase _dialog, str _controlName)
{
return _dialog.formRun().control(_dialog.formRun().controlId( _controlName));
}
private void setDialogOkButtonEnabled(DialogRunbase _dialog, boolean _isEnabled)
{
FormControl okButtonControl = this.getFormControl(_dialog, OkButtonName);
if (okButtonControl)
{
okButtonControl.enabled(_isEnabled);
}
}
|
And in the run method we perform the procedure to
process the imported data.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| public void run()
{
try
{
ttsbegin;
FileUpload fileUploadControl = this.getFormControl(eMDdialog, FileUploadName);
FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult() as FileUploadTemporaryStorageResult;
if (fileUploadResult != null && fileUploadResult.getUploadStatus())
{
//DO THE ACTION
}
ttscommit;
}
catch (Exception::Deadlock)
{
retry;
}
}
}
|