3

I am new to AX, and I am struggling with the basics.

My requirement is to save the record in a table from form controls on a button click event. What is the best approach?

Because I also see "Override" method "CreateRecord". If I go with "CreateRecord" method, then is it possible invoke the method in "Button Click Event"?

peterh
  • 11,875
  • 18
  • 85
  • 108
Ax Learner
  • 31
  • 1
  • 2
  • 2
    Hi welcome to Stackoverflow, please read [ask] for guidelines for posting questions which will be well received – Mick Jul 31 '17 at 04:10
  • Try this blog http://instructorbrandon.com/tutorial-beginning-dynamics-ax-development-with-forms-and-x-series/ and https://dynamicsuser.net/ax/m/tools/267486/download – Pradeep Muttikulangara Vasu Jul 31 '17 at 13:56
  • 1
    @PradeepMuttikulangaraVasu I would be careful with the second link, the material is for a previous version (4.0 I think). – FH-Inway Jul 31 '17 at 16:16
  • Following [these](https://meta.stackoverflow.com/a/291370/1783163) simple rules could improve your questions a lot. I suggest to follow them. I partially fixed your question now, but I can't be with you every time :-) – peterh Jul 31 '17 at 16:56

1 Answers1

2

In form you need to add a Button, then expand, right click in methods, Override method and select Clicked.

enter image description here

Here put your code, For example:

void clicked()
{
    TableExample TableExample;

    ;

    TableExample.clear();//clear fields
    TableExample.Field1 = "Your Value 1";
    TableExample.Field2 = "Your Value 2";
    TableExample.Field3 = "Your Value 3";
    TableExample.Field4 = "Your Value 4";
    TableExample.Insert();//Insert in table

    info("Record create");//Display a message (Optional, only an example)

    super();
}
Jonathan Bravetti
  • 2,228
  • 2
  • 15
  • 29
  • Nice example Jonathan. However I noticed this works when the form is not directly linked to a table as datasource(the one ending in _ds). In that particular situation I was able to accomplish this by updating the form datasource field and not the table itself. Correct me if I'm wrong. – Roman Gherta Feb 10 '18 at 04:52