Insert method in Dynamics AX?

Hi,

I need to insert some customization field value in ax form when clicking save button. Customisation field value get from using find method from different table. How its possbile to insert that field also with same datasource without duplicate in AX 2009.

Thanks in advance

I’m afraid I don’t understand your question. Could you give us a concrete example?

Hi Martin,

I created one form using datasource. i have some customization field which is not related to that datasource, i find that record from find() method. i need to insert that records also when click save icon in form. How to write the code for insert that customization fields in write() method or any other way in same data source(table)??

Because if i wirte insert coding in write() method means it insert twice(duplicate),

Thanks

If it gets inserted twice in write(), I assume you not only call super() (where AX saves the record), but also call insert(), which obviously inserts another record. You should set the field value before super() and leave all saving to AX.

No martin, am not calling insert() before or after super(). I just insert field values using insert query after call super(). please can you give one example how to set the field value(insert) before super()??

Thanks for your support.

I’m not sure what you mean by the “insert query”, nevertheless you shouldn’t insert anything. It creates a new record, as you already found, because AX already inserted the record in super(). Doing another insert must lead to creation of a new record.

An example of a field assignment is myTable.MyField = UnboundStringEdit.text();

yes martin this same field asignement only i did before. but not inserting the data.

Thanks

I’m sorry, but this description of the problem isn’t sufficient for me to say what you have wrong there. Please tell me more.

Sorry martin.

created a new form with datasource, have a grid with 17 fields. one field is combo box(EDT) . If i choose any of the value from combo, other 3 field getting the value from that related table. this i did using find() method. now i need to insert these three field value(find()) also in the same table(datasource).

Thanks.

I meant the problem you mentioned in your previous reply (“this same field asignement only i did before. but not inserting the data”). I thought you would explain what exactly you did, what exactly happened and what you found when you debugged your code in debugger.

in write() :

newtableasset _asset

_asset.description = field3.text();

_asset.model = field4.text();

_asset.range = field5.text();

super();

When i debug. value passing to that related field perfectly.

That’s nice, but you’re not assigning values to the buffer which is saved by the write() method. You created a new local buffer which will be thrown away at the end of the method without affecting anything.

Look at the name of the datasource which the method belongs to. There is a variable (automatically created by AX) with the same name, representing the active buffer. For example, if your datasource is called Asset, use the asset variable (asset.Description = …).

Thanks a lot martin. It works.