Insert data on a table Dynamics ax

1.9k views Asked by At

I have a problem when I try to insert some data on a table, I send all the values correct I think from a button, and my class catch all of them, even when I debug I can see all the values, all of them are inserted except 1, like observation I added that field on the table after the others, sometimes the fields recive some numbers but are not the numbers what I insert, numbers strangers like 7209071 and I'm trying to inser 1

this is my code on my button where I send the values:

_ClassX.MethodInsert(
    Var,   //int
    Var2,  //string
    Var3,  //string
    Var4,  //int
    Var5   //int
);
TableX_ds.research();

And here is the method

public void BBP_InsertVenta(int Var1, str Var2, str Var3, int Var4, int Var5){
_TableX.FieldOnTable1=Var1;
_TableX.FieldOnTable2=Var2;
_TableX.FieldOnTable3=Var3;
_TableX.FieldOnTable4=Var4;
_TableX.FieldOnTable5=Var5; //This line is commented
_TableX.FieldOnTable6=Var5;
_TableX.insert();}

Is curious before have the field6, I was trying first insert on the field5 but after hours trying, I created the field6, but doesn't work again, the funny thing here is when I comented that field and try with the field6 the field5 recibe numbers like 7209071 but not all the time sometimes recibe empty values or 0

2

There are 2 answers

1
Alex Kwitny On

It could be because you're passing .Net values and not casting. In your AX method you could try changing it to this:

public void BBP_InsertVenta(System.Int32 _Var1, System.String _Var2, System.String _Var3, System.Int32 _Var4, System.Int32 _Var5)
{
    int Var1 = _Var1; // Cast to AX type
    str Var2 = _Var2; // Cast to AX type
    str Var3 = _Var3; // Cast to AX type
    int Var4 = _Var4; // Cast to AX type
    int Var5 = _Var5; // Cast to AX type

    // The below code looks like a snippit and we're missing something
    _TableX.FieldOnTable1=Var1;
    _TableX.FieldOnTable2=Var2;
    _TableX.FieldOnTable3=Var3;
    _TableX.FieldOnTable4=Var4;
    _TableX.FieldOnTable5=Var5; //This line is commented
    _TableX.FieldOnTable6=Var5;
    _TableX.insert();
}
0
Celeste On

What does the fields in the table represent. Are they linked to extended data types? Are the datatypes that you’re passing exactly the same as the data types in your table?

If for example field FieldOnTable1 is of type int64, and you pass a normal int to it, the data will look different.

Why are you doing TableX_ds.research() from a class? You would normally do that in a form if the data from the datasource has changed.

Is this method on a form, in the click event of the button, or have you written a class to where you pass values to from the form?