X++ Code for Dialog Box in Dynamics 365

Hi,

X++ Code for Dialog Box in Dynamics 365

1. Yes or No Dialog Box

public static void DialogBox(EventHandlerResult _res)
    {
        DialogButton                            diagBut;
        boolean resUser=false;
   
            str strMessage = "Do you want to update or not?";

            str strTitle = "Update" ;

            diagBut = Box::yesNo(strMessage, DialogButton::No,  strTitle);

            if (diagBut == DialogButton::No)
            {
                resUser=true;
            }
            else if(diagBut == DialogButton::Yes)
            {
                resUser=false;
            }

        }

2.  Display Dialog 

Add a Runnable Class and add below code in it below code is for work qty display (Modify as you need)

class shyamSampleDialogWork extends RunBase
{
    DialogField fieldwhsWorkId;
    DialogFIeld fieldwhslineNum;
    DialogFIeld fieldItemId;
   
    WHSWorkInventTrans    workInventTrans;

    WHSWorkId whsWorkId;
    WHSWorkStatus whsWorkStatus;
    LineNum lineNum;
    ItemId itemid;

    public Object Dialog()
    {
        Dialog dialog;
        ;

        dialog = super();

        // Set a title for dialog
        dialog.caption( 'Simple Dialog');

        // Add a new field to Dialog
        fieldwhsWorkId = dialog.addField( extendedTypeStr(WHSWorkId), 'Work Id' );
        fieldwhslineNum = dialog.addField( extendedTypeStr(LineNum), 'Line Num' );
        fieldItemId = dialog.addField( extendedTypeStr(ItemId), 'Work Item Id' );
   
        return dialog;
    }

    public boolean getFromDialog()
    {
        // Retrieve values from Dialog
        whsWorkId = fieldwhsWorkId.value();
        lineNum=fieldwhslineNum.value();
        itemid = fieldItemId.value();
   
        return super();
    }

    public void run()
    {
        // Set Dialog field value to find CustTable
        select firstonly workInventTrans where workInventTrans.WorkId== whsWorkId && workInventTrans.LineNum==lineNum && workInventTrans.itemid== itemid;

        if (workInventTrans)
        {
            info( strFmt('%1 -- %2 -- %3 -- Work Qty  %4 ' , workInventTrans.WorkId, workInventTrans.linenum,itemid  ,workInventTrans.Qty ));
     
        }
        else
        {
            error( 'Work is not found!');
        }
    }

    public static void main(Args _args)
    {
        shyamSampleDialogWork sampleDialogWrk  = new shyamSampleDialogWork ();

        // Prompt the dialog, if user clicks in OK it returns true
        if (sampleDialogWrk .prompt())
        {
            sampleDialogWrk .run();
        }
    }

}

Reference

Comments

  1. Hi, for Enum? in this part: "dialog.addField(", if this "extendedTypeStr(" say error, thanks...

    ReplyDelete
    Replies
    1. dialog.addField(enumstr(NoYes), "@SYS12898", "@SYS50976");

      Delete
  2. I just need to say this is a well-informed article software development in chennai

    ReplyDelete

Post a Comment