0

I want to initialize a value of an edit method inside the init method of form, i wrote this:

[Form]
public class foo extends FormRun
{
    str                                      paymTermId;


   public void init()
   {
      
       CustTable custTable = CustTable::find("DE-001");

       paymTermId = custTable.paymTermId;                          
       super();
   }

    edit str edtpaymTermId(boolean set, str _paymTermId)
    {

        if (set)
        {
             paymTermId= _paymTermId;
        }
        return paymTermId ;
    }
 }

But when i open the form the control remains empty.

any suggestions?

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
OiRc
  • 1,602
  • 4
  • 21
  • 60
  • Edit methods are usually placed on a table or form data source. Your edit method is defined on the form and sets _a class variable_ instead of _a table / data source field_. Here is an AX2012 [example](http://d365technext.blogspot.com/2018/08/edit-method-d365fo.html) that could be converted to AX365. Make sure to set the edit method on the form control. Side note: why do you use an edit method instead of data source field for your control (an edit method is not required to initialize a data source field)? – Sander Oct 26 '20 at 18:18

2 Answers2

1

I tried to reproduce the issue, but was not successful. For me, when opening the form, the control shows a value.

A possible reason why it is not working for you could be that you open the form in the wrong company. In your code, you retrieve the value to display in the control from the payment term of customer DE-001. This customer exists in company USMF in the Contoso demo data and has payment term Net10. If the form is opened in this company, the value is shown in the control. If you are in another company (e.g. DAT), no value is shown.

enter image description here

FH-Inway
  • 4,432
  • 1
  • 20
  • 37
0

I see 2 things that are wrong:

  1. You are setting the value BEFORE super(). It should be after.
  2. You SHOULDN'T initialize the value via field, you should do it calling edit method. Edit methods have a boolean SET parameter which can simulate a call for setting a value.
Clandes
  • 61
  • 2
  • 7