Khashayar
Khashayar

Reputation: 47

Creating a button with a dialog in AX 2012

I want to make a Button.

I have a EDT "Resigning", which can't be edited, it only can be edited once and that when I press the button. When clicking the button a Dialog shall Pop up where I can type in the date.

I have to write a class I think, but I am struggling a lot...

With Kind Regards

Khashayar

Upvotes: 0

Views: 3582

Answers (2)

Aliaksandr Maksimau
Aliaksandr Maksimau

Reputation: 2281

To prevent from overwriting existing value you can modify your method as following:

public void clicked()
{
    Dialog                     dialog;
    DialogField                dialogDate;
    date                       newDate;    
    ;

    if (EmploymentTable.Resigning == dateNull())
    {
        dialog     = new Dialog("Set new date");
        dialogDate = dialog.addField(ExtendedTypeStr("YourEDTName"), "New date:");        
        if (dialog.run())
        {    
            newDate = dialogDate.value(); //Get value of new date.        
            //Here code to update your table                
        }
    }
    else
    {
        warning("Value already exists.");
    }
}

The code above is checking whether value already exists, before allowing to assign new value.

More better approach is disabling the button if value already exists. To do this write a method to disable/enable your button and call it in active method on form datasource.

Upvotes: 0

Jonathan Bravetti
Jonathan Bravetti

Reputation: 2238

you can write the code in clicked method of the button.

Here a simple job to do that:

static void StackOverflow(Args _args)
{
    Dialog                     dialog;
    DialogField                dialogDate;
    date                       newDate;    
    ;
    dialog     = new Dialog("Set new date");
    dialogDate = dialog.addField(ExtendedTypeStr("YourEDTName"), "New date:");        
    if (dialog.run())
    {    
        newDate = dialogDate.value(); //Get value of new date.        
        //Here code to update your table                
    }
}

Upvotes: 1

Related Questions