0
votes

I have created a class dialog, which has 1 select field, called ReasonId.

In this class I have a method returning a value:

ReasonId  reasonId()
{
    return reasonId::ValueX;
}

Also, I have a method making use of a find method, with a filter based on the above enum value:

ReasonId  documentReasonId()
{
    return DocumentReasons::findByReason(this.reasonId()).Name;
}

In the dialog method, I am trying to display the values returned by the find method, there are more values in the table, but since I'm searching based on the Reason, I only want to display these values:

    public Object dialog()
{
    DialogGroup     dialogGroup;
    ;
    dialogRunbase = super();
    dialogGroup = dialogRunbase.addGroup();
    dialogGroup.caption("CaptionLabel");
    dialogReasonId  = dialogRunbase.addFieldValue(this.reasonId(), "Label1","Label2");
    return dialogRunbase;
}

The way I have configured it now, is to show my goal in this dialog, I am not sure how to accomplish this.

1
Can your table DocumentReasons contain multiple records with the same ReasonId? - 10p
Yes it can, so it can be that it has to return multiple names, with the same ReasonId. - Mark Van
So how exactly do you want to display multiple DocumentReasons.Name values - in a grid? in a multiline text box? in another way? - 10p
I would like to display the name value in a dropdown list, where only 1 reason can be selected. - Mark Van

1 Answers

2
votes

I don't see the code in your method DocumentReasons::findByReason(), whether it fetches a single record (if the firstOnly keyword is used in there) or multiple records. So I am not going to use this method in the example below.

Since you want to use a dropdown list, the FormComboBoxControl should be used. You can start with something like this and amend as required:

public Object dialog()
{
    DocumentReasons documentReasons;
    FormComboBoxControl comboBox;
    Counter i;

    dialogRunbase = super();

    select count(RecId) from documentReasons
        where documentReasons.ReasonId == ReasonId::ValueX;

    comboBox = dialogRunbase.curFormBuildGroup().addControl(FormControlType::ComboBox, 'testName');
    comboBox.items(documentReasons.RecId);

    while select Name from documentReasons
        where documentReasons.ReasonId == ReasonId::ValueX
    {
        i++;

        comboBox.item(i);
        comboBox.text(documentReasons.Name);
    }

    return dialogRunbase;
}

I haven't tested it in AX but it should work.