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...
Suggested Answer

Issue Linking Sales Invoice Header with Sales Header for Custom Report

(0) ShareShare
ReportReport
Posted on by

Hi All, hopefully a simple request here. When generating a custom invoice I am in need to pull data from the original sales order. I thought this would be as easy as linking the Sales Invoice Header identified as "Header" below and the Sales Header. I have searched the topic and haven't found anyone running into the issue so my guess is it is something specific to what I am doing wrong. Any help would be greatly appreciated. -Ben

pastedimage1587524574868v2.png

pastedimage1587524550957v1.png
I have the same question (0)
  • keoma Profile Picture
    32,729 on at

    in the sale line linking of document type is missing.

    what in detail do you want to do?

  • Community Member Profile Picture
    on at

    Hi Franz, I’ve never had to use the doctype before when linking lines to their document. The issue is I need to pull details from the sales order when generating the invoice and I’m creating a new report to do it. All fields from the Invoice dataitems are pulling fine. It’s when I introduce Sales Header that it I’m not able to get the extra data. 

  • keoma Profile Picture
    32,729 on at

    please publish the whole code, maybe with some comments to get a better understanding.

    what do you mean with "when I introduce Sales Header that it I’m not able to get the extra data."?

  • Community Member Profile Picture
    on at

    It's over 1,000 lines, you want the whole thing?

    I mean that generating a sales invoice using normal invoice related data from the Sales Invoice Header and Sales Invoice Line works appropriately. When using dataitemlink and dataitemlinkreference to join the Sales Header dataitem to the Sales Invoice Header dataitem I am not able to pull back data in the Sales Header.

  • Community Member Profile Picture
    on at

    I believe you could change the security premission on the sales comment line table to allow read and insert premission for the users, but not modify or delete, this would let them see and create comments but not edit or delete them,  this would be the way to do it without any program changes,  You could give a selected user edit and delete permissions so that someone could still make changes, just not all users

    I am not a programmer so I will leave the method of doing this in code to others., but the basic principle would be to add a field to the sales comment table = userid, and then have code that checked user id and only let the user who created the comment to be the only one who could edit it.

  • Community Member Profile Picture
    on at

    Here's the start of report. I have tried encapsulating the dataitem("Sales Header".. inside the dataitem(Header; "Sales Invoice Header") like you would an Sales Invoice Line. In this example I moved it out to see if that was the issue. Thoughts?

    report 50125 EightyAcresSalesInvoice

    {

       RDLCLayout = './80AcresSalesInvoice.rdlc';

       WordLayout = './80AcresSalesInvoice.docx';

       Caption = '80 Acres Sales - Invoice';

       DefaultLayout = Word;

       EnableHyperlinks = true;

       Permissions = TableData "Sales Shipment Buffer" = rimd;

       PreviewMode = PrintLayout;

       WordMergeDataItem = Header;

       dataset

       {

           dataitem("Sales Header"; "Sales Header")

           {

               DataItemLinkReference = "Header";

               DataItemLink = "No." = Field("Order No.");

               column(No_; "No.") { }

               column(Sell_to_Customer_Name; "Sell-to Customer Name") { }

               dataitem("Sales Line"; "Sales Line")

               {

                   DataItemLinkReference = "Sales Header";

                   DataItemLink = "Document No." = field("No.");

                   column(OrderQuantity; Quantity) { }

                   column(OrderQuantityShipped; "Quantity Shipped") { }

                   column(Description; Description) { }

                   Column(Unit_of_Measure; "Unit of Measure") { }

                   column(Allow_Line_Disc_; "Allow Line Disc.") { }

                   column(Unit_Price; "Unit Price") { }

                   column(Amount; Amount) { }

               }

           }

           dataitem(Header; "Sales Invoice Header")

           {

               DataItemTableView = SORTING("No.");

               RequestFilterFields = "No.", "Sell-to Customer No.", "No. Printed";

               RequestFilterHeading = 'Posted Sales Invoice';

               column(CompanyAddress1; CompanyAddr[1])

               {

               }

               column(CompanyAddress2; CompanyAddr[2])

               {

               }

               column(CompanyAddress3; CompanyAddr[3])

               {

               }

               column(CompanyAddress4; CompanyAddr[4])

               {

               }

               column(CompanyAddress5; CompanyAddr[5])

               {

               }

               column(CompanyAddress6; CompanyAddr[6])

               {

               }

               column(CompanyAddress7; CompanyAddr[7])

  • Suggested answer
    keoma Profile Picture
    32,729 on at

    i developed following code, that works ... in general, but your business logic makes no sense, because after posting the sales order, the sales order is removed (the sales header record). so you will not find any sales header record with order no.=<what ever>, the sales header record is archived.

    report 50100 "Copy Sales Invoice Data"

    {

       ProcessingOnly = true;

       dataset

       {

           dataitem(InvHeader; "Sales Invoice Header")

           {

               RequestFilterFields = "No.";

               dataitem(SalesHeader; "Sales Header")

               {

                   DataItemLinkReference = InvHeader;

                   DataItemLink = "No." = field("Order No.");

                   trigger OnAfterGetRecord()

                   begin

                       CustField := InvHeader.CustField; // set the value from sales inv. header to sales header

                       Modify();

                   end;

               }

               trigger OnAfterGetRecord()

               begin

                   InvHeader.testfield("Order No.");

                   // set a sample value in invheader

                   InvHeader.CustField := 12;

                   InvHeader.Modify();

               end;

           }

       }

    }

  • Community Member Profile Picture
    on at

    And I believe that might be the silly missing link. I was using active Sales Header instead of the link to Archive. Something simple I overlooked. Thank you, will give that a shot and mark this as the answer if it works.

  • keoma Profile Picture
    32,729 on at

    does it work? if yes, please verify the thread.

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 3,010

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,270 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,085 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans