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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

How to get Unique Primary Key of the Record (Sales Invoice No.) from Sales Header Table

(0) ShareShare
ReportReport
Posted on by 2,122

Hi,

I want to fetch Unique Primary Key of the Record (Sales Invoice No.), for a selected record from Sales Header Table & Pass it as a parameter to Power Automate flow. I got an error it shows only last record ID but I want to fetch Sales Invoice No for a selected record. Please Provide Any suggestions so that I can fetch particular record NO. from sales header table.

Thank You.

pastedimage1684158455356v1.png     pastedimage1684158495184v2.png

pastedimage1684158669122v3.png

I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    61,223 Super User 2026 Season 1 on at

    Where did you write the code? and I didnt see any parameter that is passed to myprocedure.

  • Suggested answer
    Govinda Kumar Profile Picture
    2,310 Moderator on at

    This is because you are iterating through all the invoices and at the end, you are getting the last invoice number to your variable SalesHeaderNo

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

    Hi,

    I have not seen from where you are calling this Myprocedure function. Can you show your complete code here?

  • Inkey Solutions Profile Picture
    2,122 on at

    Codeunit1.png

    pastedimage1684212376267v1.pngCodeunit-2.png

    Code Unit

    PageExt1.pngPageExt2.png

    Page Ext

  • Inkey Solutions Profile Picture
    2,122 on at

    I have Upload the Full code Below in my Community Page.

  • Inkey Solutions Profile Picture
    2,122 on at

    Yes , if there is a way to do ,Can you please watch in these community  I mention a whole code below and I want to  fetch  the "Sales invoice No." for a selected Record.

  • Verified answer
    Govinda Kumar Profile Picture
    2,310 Moderator on at

    If you want to fetch a specific Sales Invoice No., you need to specify the invoice number you want to fetch. I don't have information about the parameters or criteria you want to use to fetch the current record or a specific invoice number..

            SalesHeder.SetFilter("Document Type", '=%1', "Sales Document Type"::Invoice);
            SalesHeder.SetFilter("No.", '=%1', 'INV-1089801'); // 'INV-1089801' your invoice number
            if (SalesHeder.Find('-')) then begin
                SalesHeaderNo := SalesHeder."No.";
            end;

    Please make sure to modify the code with the appropriate invoice number or criteria according to your requirement.
    Regards

  • Suggested answer
    Mohana Yadav Profile Picture
    61,223 Super User 2026 Season 1 on at

    Pass SalesHeader parameter to MyProcedure.

    procedure MyProcedure(SalesHeader: Record "Sales Header") responsetext: text

    make it global by removing local infront of the procudure

    you dont need lines 31 to 42 in the MyProcedure

    You can use SalesHeader parameter that is passed to function in your code.

    call the procedure from your page action

    Storetext := FlowTest.MyProcedure(Rec);

    Storetext is text variable to store the responsetext

  • Inkey Solutions Profile Picture
    2,122 on at

    I have try For Static Record , I need help for a selected record in whole page dynamics in AL Code .

  • Verified answer
    Govinda Kumar Profile Picture
    2,310 Moderator on at

    Ok I got it what you mean now.. you forgot to set TableNo property in your codeunit.. by setting the TableNo property, using a global variable, and passing the CurrentRecord as a parameter in your codeunit, you can get the selected current record invoice number in your page.

    codeunit 50129 INK_GetPostURL
    {
        TableNo = "Sales Header"; // set the TableNo property
    
        trigger OnRun()
        begin
            SalesHeaderCurrentRecord := Rec;
            MyProcedure();
        end;
    
        local procedure MyProcedure()
        var
            errors: Record "Error Message" temporary;
            SalesHeder: Record "Sales Header";
            SalesHeaderNo: Code[20];
        begin
            SalesHeaderNo := SalesHeaderCurrentRecord."No.";
            
            // If your requirement is only to get the selected invoice number you don't need to use set filter in your MyProcedure() to get the current record..
            
            // SalesHeder.SetFilter("Document Type", '=%1', "Sales Document Type"::Invoice);
            // SalesHeder.SetFilter("No.", '=%1', SalesHeaderCurrentRecord."No."); // 'INV-1089801' your invoice number
            // if (SalesHeder.Find('-')) then begin
                // SalesHeaderNo := SalesHeder."No.";
            // end;
        end;
    
        var
            SalesHeaderCurrentRecord: Record "Sales Header"; // Sales Header Record variable for current record
    }
    
    
    // in your action you need to pass the current record as a parameter.
    
            FlowTest.Run(Rec);

    Please make sure you adjust the code with the appropriate logic and filters according to your requirement
    Regards

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,496 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 961 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 870 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans