How to pass record args from Main method to Run method using Extend RunBase ax 2012?

Hi all,

I have problem in passing record args from main method to Run method.

I will share my code here so you can understand what i am trying to achieve.

class WIZDRRepDialog extends RunBase
{

    DialogFIeld repIdField, repReasonField;
    DRRepParameters   dRRepParameters;

    DRRepNumSeq dRRepNumSeq;
}

protected Object dialog()
{
   DialogRunBase   dialog;
    FormStringControl ctrl1;

    dialog = super();
    repIdField    = dialog.addField(ExtendedTypeStr(DRRepNumSeq), "Select Reason: ");   
    
    ctrl1 = repIdField.control();
    ctrl1.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(WIZDRRepDialog, lookupTest), this);

    return dialog;

}
public boolean getFromDialog()
{
    // Retrieve values from Dialog
    dRRepNumSeq = repIdField.value();

    return super();
}

protected void lookupTest (FormStringControl _control)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(DRRepParameters), _control);

    sysTableLookup.addLookupField(fieldNum(DRRepParameters, Key));
    sysTableLookup.addLookupField(fieldNum(DRRepParameters, Reasons));

    queryBuildDataSource = query.addDataSource(tableNum(DRRepParameters));
    sysTableLookup.parmQuery(query);

    sysTableLookup.parmTmpBuffer(DRRepParameters);  //set our populated buffer!
    sysTableLookup.performFormLookup();
}
public static void main(Args _args)
{
    WIZDRRepDialog repCreate = new WIZDRRepDialog();
    
    // Prompt the dialog, if user clicks in OK it returns true
    if (repCreate.prompt())
    {
        repCreate.run();
    }
}
public void run()
{
    Args _args = new Args();
    
    str strMessage = "PAULIT-ULIT!? KAYA KA NASASAKTAN EH! \nYour Trial is Excedeed! \nPlease coordinate with CNC Department.";
    str strTitle = "DR Request Reprint Form";
    Notes   notes;
    
    
    
    WIZDRRepDialog controller = new WIZDRRepDialog();
    CustInvoiceJour custInvoiceJour;
    wizRequestTable requestTable;


    dRRepParameters = DRRepParameters::find(dRRepNumSeq);
    
    if (dRRepParameters)
    
        {
            if(_args.dataset() == tableNum(CustInvoiceJour))
            {
                custInvoiceJour = _args.record();
                if (wizRequestTable::find(custInvoiceJour.RecId, custInvoiceJour.dataAreaId).ApprovalStatus != DRApproval_Status::ForApproval
                || wizRequestTable::find(custInvoiceJour.RecId, custInvoiceJour.dataAreaId).ApprovalStatus == DRApproval_Status::None)
                    {
                        if (custInvoiceJour.CountPrint != 2)
                        {
                            requestTable.Reason = dRRepParameters.Reasons;
                            requestTable.RepId = dRRepParameters.Key;
                            requestTable.InvoiceId = custInvoiceJour.InvoiceId;
                            requestTable.SalesId = custInvoiceJour.SalesId;
                            requestTable.CustInvoiceJourId = custInvoiceJour.RecId;
                            requestTable.ApprovalStatus = DRApproval_Status::ForApproval;

                            ttsBegin;
                            requestTable.insert();
                            //salesTable.update();
                            ttsCommit;
                            Box::info("Sucessfully sent!", "Request DR Reprinting");
                        }
                        else
                            {
                                Box::warning(notes, strTitle, '');
                        }
                }
                else
                    {
                        Box::warning(strFmt('Invoice Id %1 is still pending for approval', custInvoiceJour.InvoiceId),strTitle,'');
                }
            }
            else
                {
                    error('Reprint Id is not found!');
            }
        }
        else
            throw error("Incorrect table record for processing");
    super();
}

If you have better ideas or suggest, please let me know.

Thank you in advance.

I don’t see any code for serialization, therefore no variables will be passed from client (= dialog) to server, where the logic is executed. This is clearly a bug.

I recommend you forget this old framework and use the SysOperation framework instead; it will serialize and deserialize data contract classes for your. If you insist on using the legacy framework, study how to implement pack() and unpack() methods.

Thanks for the replay martin.

I don’t know how to use pack() and unpack methods

That’s why recommend that you don’t worry about it and use the newer framework which handles this for you automatically. And it has other advantages, such as the separation of concern, dialog generation and additional execution modes.

By the way, your title says that you want to pass values from main() but you don’t have anything like that there. You also never populate DRRepParameters. It seems that what you showed us is seriously incomplete; we can only guess what you intend to develop there in future.

can you share sum tutorial?

Honestly i don’t how will pass the Args in the run method.

in the run method you will this code

dRRepParameters = DRRepParameters::find(dRRepNumSeq);

if (dRRepParameters)

{
if(_args.dataset() == tableNum(CustInvoiceJour))
{
custInvoiceJour = _args.record();

i just declare args in run method so that the error disappear, but the truth is the code above is error.

By the way i am calling this class using menuitembutton from the form (CustinvoiceJournal)

Look at SysOperation introduction, for example.

Can you give example with lookup using SysOperation, see below image.

0825.Capture.JPG

Hi Martin.

Problem solve!

I use the same code, but i reconstruct it…

by creating a new method at pass the records.

private void insertRequestTable(CustInvoiceJour custInvoiceJour)
{
    wizRequestTable requestTable;
    dRRepParameters = DRRepParameters::find(dRRepNumSeq); 
    
    if (dRRepParameters)
    {
        requestTable.Reason = dRRepParameters.Reasons;
        requestTable.RepId = dRRepParameters.Key;
        requestTable.InvoiceId = custInvoiceJour.InvoiceId;
        requestTable.SalesId = custInvoiceJour.SalesId;
        requestTable.CustInvoiceJourId = custInvoiceJour.RecId;
        requestTable.ApprovalStatus = DRApproval_Status::ForApproval;
        
        ttsBegin;
        requestTable.insert();
        //salesTable.update();
        ttsCommit;
    }
    else
        throw error("Incorrect table record for processing");

and add a line of code in main() method.

repCreate.insertRequestTable(custInvoiceJour);

Thank you for your time.