And I tried to follow the code in my new class, but I got few errors which I don't know how to resolve it.
So, based on the mentioned blog, I tried to compile it together because it seems the code are in pieces, and come up with this:
public class importCSV extends RunBase{ private str availableTypes = /.csv/; private const str OkButtonName = 'OkButton'; private const str FileUploadName = 'FileUpload'; str textFile; DialogRunBase Dialog; public Object dialog() { DialogGroup dialogGroup; FormBuildControl formBuildControl; FileUploadBuild dialogFileUpload; Set enumSet = new Set(Types::Enum); ; dialog = super(); dialogGroup = dialog.addGroup(/File path/); formBuildControl = dialog.formBuildDesign().control(dialogGroup.name()); dialogFileUpload = formBuildControl.addControlEx(classstr(FileUpload), FileUploadName); dialogFileUpload.style(FileUploadStyle::MinimalWithFilename); dialogFileUpload.baseFileUploadStrategyClassName(classstr(FileUploadTemporaryStorageStrategy)); dialogFileUpload.fileTypesAccepted(availableTypes); dialogFileUpload.fileNameLabel(/@SYS308842/); return dialog; } protected void setDialogOkButtonEnabled(DialogRunbase _dialog, boolean _isEnabled) { FormControl okButtonControl = this.getFormControl(_dialog, OkButtonName); if (okButtonControl) { okButtonControl.enabled(_isEnabled); } } protected FormControl getFormControl(DialogRunbase _dialog, str _controlName) { return _dialog.formRun().control(_dialog.formRun().controlId( _controlName)); } protected void uploadCompleted() { FileUpload fileUpload = this.getFormControl(dialog, FileUploadName); fileUpload.notifyUploadCompleted -= eventhandler(this.UploadCompleted); textFile = fileUpload.fileName(); this.setDialogOkButtonEnabled(dialog, true); } /// Disables the dialog Ok button until the file upload is complete. public void dialogPostRun(DialogRunbase _dialog) { FileUpload fileUpload = this.getFormControl(_dialog, FileUploadName); fileUpload.notifyUploadCompleted = eventhandler(this.uploadCompleted); this.setDialogOkButtonEnabled(_dialog, false); } void processCSVFile() { #File container currentLine; int totalOfLines; CommaTextStreamIo localStream; Num number; int fileLineNumber; FileUpload fileUploadControl = this.getFormControl(dialog, FileUploadName); FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult(); if (fileUploadResult != null && fileUploadResult.getUploadStatus()) { textFile = fileUploadResult.getDownloadUrl(); } localStream = CommaTextStreamIo::constructForRead(File::UseFileFromURL(textFile)); if (localStream.status() != IO_Status::Ok) { throw error(strfmt('Is not possible to open the file. Error %1',enum2str(localStream.status()))); } localStream.inFieldDelimiter(///,/); localStream.inRecordDelimiter(///); currentLine = localStream.read(); fileLineNumber ; if(conlen(currentLine) == 1) { throw error('Is not possible to import the file, incorrect format'); } currentLine = localStream.read(); fileLineNumber ; while(currentLine) { number = conPeek(currentLine,1); info(strFmt(/Number : %1/,number)); currentLine = localStream.read(); } } public static void main(Args _args) { importCSV importClass = new importCSV(); importClass.processCSVFile(); } }
So I have these errors :
About the Invalid token 'eventhandler' I do notice a weird statement in two void as below:
May I know what actually needed and what these code trying to do ?
Also about the other 2 Invalid token, I'm not sure why in the error log pointing to line number which I think it is not possible to have that wrong code.
May I get help and guidance how to resolve this ?
Many thanks in advance.