Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Ax 2009 and c# pass data

Posted on by 160

Hi!:

I am having an issue with Ax 2009 and C#.

Passing simple string values is not a problem.

But, when I need to pass a data type List, Ax "don't see"

C# method.

For example:

The method in C# is the following:

using System.Xml.Serialization;

[XmlArray(IsNullable = true)]
[XmlArrayItem("formaPago")]
public FormaPago[] listaFormaPago
{
    get
    {
        return listaFormaPagoField;
    }
    set
    {
        listaFormaPagoField = value;
    }
}

In Ax, how I pass this data?.

 totalesSubTotales.set_listaFormaPago();

the parameter between parenthesis show me in Ax:

void set _ListaFormaPago(FormaPago[] value)

Regards!

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 225,588 Super User on at
    RE: Ax 2009 and c# pass data

    If your question has been answered, please don't forget to verify the answer. It's done by clicking Did this answer your question? > Yes on the reply (or replies) answering the question.

  • José Quintero Profile Picture
    José Quintero 160 on at
    RE: Ax 2009 and c# pass data

    You are very right!

    Thanks!

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 225,588 Super User on at
    RE: Ax 2009 and c# pass data

    I see no (5) in your code. Do you mean (1)?

    Sorry, the right syntax seems to be FormaPago[1]().

  • José Quintero Profile Picture
    José Quintero 160 on at
    RE: Ax 2009 and c# pass data

    Hello:

    Morph X put in redline when I add (5) to AXV5ElectronicInvoice.TfhkaPaWebService.FormaPago[]

    in the initialization of array in declaration.

       AXV5ElectronicInvoice.TfhkaPaWebService.FormaPago[] array   = new  AXV5ElectronicInvoice.TfhkaPaWebService.FormaPago[](1);

    Syntax error show me.

    I am in Ax 2009.

    Regards

  • Martin Dráb Profile Picture
    Martin Dráb 225,588 Super User on at
    RE: Ax 2009 and c# pass data

    I disagree - AXV5ElectronicInvoice.TfhkaPaWebService.FormaPago[ isn't and array of strings. It's an array of AXV5ElectronicInvoice.TfhkaPaWebService.FormaPago.

    Where exactly do you get the syntax error?

    Do I understand correctly that this works:

    AXV5ElectronicInvoice.TfhkaPaWebService.FormaPago[] array;

    but this fails to compile?

    AXV5ElectronicInvoice.TfhkaPaWebService.FormaPago[] array = AXV5ElectronicInvoice.TfhkaPaWebService.FormaPago[](1);

  • José Quintero Profile Picture
    José Quintero 160 on at
    RE: Ax 2009 and c# pass data

    Hi Martin!:

    Well, I use your solution.

    I declare an array of type String like following:

      AXV5ElectronicInvoice.TfhkaPaWebService.FormaPago[] array;

    No problem, It accepts it.

    When I use the method in C# it accepts the array declarated before.

       totalesSubTotales.set_listaFormaPago(array);

    Before that I made the set in the array:

       array.SetValue(formaPago,0);

    But, I have a question, the unique part that does not work

    is this:

    TheNamespace.FormaPago[] array = TheNamespace.FormaPago[](5);

       AXV5ElectronicInvoice.TfhkaPaWebService.FormaPago[] array   = AXV5ElectronicInvoice.TfhkaPaWebService.FormaPago[](1);

    The Ax send me error "syntax error".

    Regards

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 225,588 Super User on at
    RE: Ax 2009 and c# pass data

    This adds formaPago object to the array as the first element (index 0):

    array.SetValue(formaPago, 0);

  • José Quintero Profile Picture
    José Quintero 160 on at
    RE: Ax 2009 and c# pass data

    Hi Martin!:

    Thanks for your prompt answer.

    Yes it is. You are right.

    It is an array of objects for "FormaPago".

    I am setting the class FormaPago in Ax no problem with this:

       formaPago.set_formaPagoFact("01");

       formaPago.set_valorCuotaPagada(strLRTrim(num2Str(abs(custInvoiceJour.InvoiceAmount),11,2,0,0)));

       formaPago.set_descFormaPago("");

    But, before to pass to totalesSubTotales.set_listaFormaPago()

    Do I need to pass formaPago object to an Array?

    How I do that in Ax 2009?.

    Regards.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 225,588 Super User on at
    RE: Ax 2009 and c# pass data

    There is no list - it's an array of FormaPago objects. You should be able to create it in this way:

    TheNamespace.FormaPago[] array = TheNamespace.FormaPago[](5);

    This creates an empty array for five elements.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,989 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,588 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans