Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Get data from a ListPart of a codeunit

Posted on by 30

Hello everyone.
I would like to get data from the ListPart "Sales Invoice Subform".
What I want to do is to get the data and put it in an xml.
I have the following code.

I hope you can help me, thanks.

codeunit 50901 "XMLtestSUBFORM"
{
    procedure XMLv4(RecordCurr: Record "Sales Header")
    var

        v_XMLDoc: XmlDocument;
        v_XMLDec: XmlDeclaration;
        v_RootNode: XmlElement;
        v_ParentNode: XmlElement;
        v_TempBlob: Codeunit "Temp Blob";
        v_Instr: InStream;
        v_OutStr: OutStream;
        v_ReadTxt: Text;
        v_Writetxt: Text;
        v_Emisor: Record "Company Information";
        v_customer: Record Customer;
        v_salesH: Record "Sales Header";
        DatosActuales: Record "Sales Header";


    begin

        DatosActuales := RecordCurr;
        DatosActuales.SetRecFilter();

        v_XMLDoc := XmlDocument.Create();
        v_XMLDec := XmlDeclaration.Create('1.0', 'UTF-8', 'no');
        v_XMLDoc.SetDeclaration(v_XMLDec);

        v_Emisor.Get();
        v_ParentNode := XmlElement.Create('Emisor', 'http://www.sat.gob.mx/cfd/4');
        v_RootNode.Add(v_ParentNode);
        v_ParentNode.SetAttribute('Name', v_Emisor.Name);
        v_ParentNode.SetAttribute('Rfc', v_Emisor."RFC No.");

        v_salesH.FindSet();
        v_ParentNode := XmlElement.Create('Receptor', 'http://www.sat.gob.mx/cfd/4');
        v_RootNode.Add(v_ParentNode);
        v_ParentNode.SetAttribute('Name', DatosActuales."Bill-to Name");
        v_ParentNode.SetAttribute('Code', DatosActuales."CFDI Export Code");

        v_TempBlob.CreateInStream(v_Instr);
        v_TempBlob.CreateOutStream(v_OutStr);
        v_XMLDoc.WriteTo(v_OutStr);
        v_OutStr.WriteText(v_Writetxt);
        v_Instr.ReadText(v_Writetxt);
        v_ReadTxt := 'name_CFDI40.XML';
        DownloadFromStream(v_Instr, '', '', '', v_ReadTxt);

    end;

}

  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 73,171 Super User 2024 Season 2 on at
    RE: Get data from a ListPart of a codeunit

    Hi, I agree with Nitin.

    If this is a new action you added to the screen, you can directly add it in "Sales Invoice Subform", which will be much easier.

    For example,

    pastedimage1674433726759v1.png

    Hope this helps as well.

    Thanks.

    ZHU

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,272 Super User 2024 Season 1 on at
    RE: Get data from a ListPart of a codeunit

    hi

    i add this

    learn.microsoft.com/.../devenv-xmlport-object

    DAniele

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: Get data from a ListPart of a codeunit

    Hi,

    you can create a xmlport direcly from sales line table and use that xmlport to export the data.

    thanks

  • Suggested answer
    Andy Sather Profile Picture
    Andy Sather on at
    RE: Get data from a ListPart of a codeunit

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    I will open this up to the community in case they have something to add.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,151 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,993 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans