web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Get data from a ListPart of a codeunit

(0) ShareShare
ReportReport
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;

}

I have the same question (0)
  • Suggested answer
    Andy Sather Profile Picture
    on at

    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.

  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    Hi,

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

    thanks

  • Suggested answer
    DAnny3211 Profile Picture
    11,397 on at

    hi

    i add this

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

    DAniele

  • Verified answer
    YUN ZHU Profile Picture
    95,729 Super User 2025 Season 2 on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans