How to access Args inside dialog() in a runbasebatch class?

Main method:

server static void main(Args args)
{
    VCInstrumentCreateForm   VCInstrumentCreateForm = VCInstrumentCreateForm::construct();

    if (!args || !args.record())
    {
        throw error(strFmt("@SYS29104", classStr(VCInstrumentCreateForm)));
    }

   
    if (VCInstrumentCreateForm.prompt())
        VCInstrumentCreateForm.run();

}

Dialog method

  • I can get the caption through ARGS inside MAIN, however cannot access it through dialog method
public Object dialog()
{
    VCInstrumentCreateForm VCInstrumentCreateForm;
    DialogRunbase   dialog= Dialog::newFormnameRunbase(formstr(VCInstrumentCreateForm),this);

    dialog = this.dialogInternal(dialog);

    //PROBLEM HERE
    //dialog.caption("...caption will be coming from an args param...");
    
    dlgBillingScheduleGrp = dialog.addGroup("Billing Schedule date:");
    dlgStartDate = dialog.addField(extendedTypeStr(TransDate), "Start date:");
    dlgStartDate.value(startDate);
    dlgEndDate = dialog.addField(extendedTypeStr(TransDate), "End date");
    dlgEndDate.value(endDate);

args is a local variable in main() method. You’ve never passed it to the VCInstrumentCreateForm object, therefore you indeed can’t use it there.

You need a variable for holding the Args object (or maybe just the record, if that’s what you’re interested in) in VCInstrumentCreateForm class, and a method that will allow you to set a value to this variable.

Then you can set the in main() like this:

static void main(Args _args)
{
    VCInstrumentCreateForm instrumentCreateForm = VCInstrumentCreateForm::construct();

    if (!_args || !_args.record())
    {
        throw error(strFmt("@SYS29104", classStr(VCInstrumentCreateForm)));
    }

	instrumentCreateForm.parmArgs(_args);
   
    if (instrumentCreateForm.prompt())
	{
        instrumentCreateForm.run();
	}
}

By the way, please always attach a tag with the version (such as AX 2009 or D365FO) when creating a new thread. There are significant differences between versions (for example, AX 2012 came with a new framework for these things), therefore knowing the version is very important for these discussions.

Hi Martin,

I tried that approach but still unsuccessful, the value of args is NULL when accessed in dialog()

server static void main(Args args)
{
    VCInstrumentCreateForm   VCInstrumentCreateForm = VCInstrumentCreateForm::construct();

    if (!args || !args.record())
    {
        throw error(strFmt("@SYS29104", classStr(VCInstrumentCreateForm)));
    }

   
    VCInstrumentCreateForm.parmArgs(args);

    if (VCInstrumentCreateForm.prompt())
        VCInstrumentCreateForm.run();

}
public Args parmArgs(Args _parmArgs = parmArgs)
{
    parmArgs = _parmArgs;
    return parmArgs;
}
public Object dialog()
{
    VCInstrumentCreateForm VCInstrumentCreateForm;
    Args _args;// = new Args();
    DialogRunbase   dialog= Dialog::newFormnameRunbase(formstr(VCInstrumentCreateForm),this);

    dialog = this.dialogInternal(dialog);

    //PROBLEM HERE_
    _args = this.parmArgs();
    //dialog.caption("...caption will be coming from an args param...");

    dlgBillingScheduleGrp = dialog.addGroup("Billing Schedule date:");
    dlgStartDate = dialog.addField(extendedTypeStr(TransDate), "Start date:

Debug set in diialog, but value returned null

pastedimage1610154258398v1.png

Which version did you say you’re using? Didn’t you read what I wrote about it?

disadvantage of RunBase framework is that you must manually implementation serialization, which is needed for transfering variables between tiers (and storing them in database for batch processing). Because you call main() on server and dialogs runs on client, the system likely create another instance on client - and because you didn’t implement serialization, your variables won’t be transfered. Please try running main() on client - that’s why I removed ‘server’ keyword from your code.

One of the benefits of SysOperation framework is that you don’t have to worry about serialization.