Import csv file using runbase class and it should have dialog

Hi Experts,

I am Importing csv file with salesid using runbase class and it should have dialog as well and if clicking ok then only the run method should trigger. Please find the below example of my code.

class MyRunBase extends RunBase
{
FileUploadTemporaryStorageResult fileUpload;

public static void main(Args _args)
{
    MyRunBase myrunbase = new MyRunBase();
    myrunbase.prompt();
    myrunbase.run();
}

public boolean prompt()
{
    
    this.fileUpload = File::GetFileFromUser() as FileUploadTemporaryStorageResult;
    
    return true;
   
}
public boolean getFromDialog()
{
    return true;
}

public void run()
{
    AsciiStreamIo file;
    Array fileLines;
    Counter counter = 0;
    str caseID;
    boolean header = true;

    try
    {
        file = AsciiStreamIo::constructForRead(this.fileUpload.openResult());

        if (file)
        {
            file.inFieldDelimiter(',');
            file.inRecordDelimiter('\r\n');
        }

        container rec;
        ttsBegin;

        while (!file.status())
        {
            counter++;
            rec = file.read();
            
            if (conLen(rec))
            {
                if (header)
                {
                    header = false;
                    continue;
                }

                SalesId = conpeek(rec, 1);

                

                 SalesTable  salesTable;

                select forUpdate salesTable
                    where salesTable.salesId == salesId;

                if (salesTable)
                {
                    salesTable.SalesStatus = NoYes::Yes;
                    salesTable.update();
                }
            }
        }

        ttsCommit;
        info("Import Done");
    }
    catch (Exception::Deadlock)
    {
        retry;
    }
}

}

This code is working fine but I would like to add a dialog here before calling the run method. How can i add this?

Thanks in advance,
Mark

You deactivated the standard logic for creating a dialog by not calling super() in prompt(). You should call super() and return the value it returns (instead of hard-coded true).

Then you’ll also need to check the return value of prompt() in main() and skip calling run() if it return false, i.e. when the user cancelled the dialog.

Thanks @MartinDrab,

How can we use the dialog field with the class’FileUploadTemporaryStorageResult’?

DialogField ImpFile = dialog.addField(extendedTypeStr(FileUploadTemporaryStorageResult),"Upload File");

But the above line is not accepting in the code.

How can I use the below ‘select file’ part inside of the dialog?

image

Thanks in advance,
Mark

You can add a FileUpload control to a dialog. For example, look at Processing an Excel file in batch using the FileUpload functionality together with SysOperationFramework. It utilizes the SysOperation dialog, but you should be able to do something similar in the old RunBase framework, if you insist on using it.