Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Need help with RunBase...
Finance forum
Under review by Community Managers

Under review

Thank you for your post! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Need help with RunBase class for import file

Posted on by
Hi guys,
 
Can I get help on creating a class for import CSV file to D365FO. I found this blog which is similar like what I needed : https://sukrut-axapta.blogspot.com/2017/09/d365fo-use-of-fileupload-control-to.html
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.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,125 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,871 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans