Skip to main content

Notifications

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

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

Posted on by 1,654

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

Categories:
  • Inkey Solutions Profile Picture
    Inkey Solutions 1,654 on at
    RE: How to get Unique Primary Key of the Record (Sales Invoice No.) from Sales Header Table

    Thank you For suggestion It works Perfectly.

  • Verified answer
    Govinda Kumar Profile Picture
    Govinda Kumar 2,203 Super User 2024 Season 1 on at
    RE: How to get Unique Primary Key of the Record (Sales Invoice No.) from Sales Header Table

    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

  • Inkey Solutions Profile Picture
    Inkey Solutions 1,654 on at
    RE: How to get Unique Primary Key of the Record (Sales Invoice No.) from Sales Header Table

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

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,127 Super User 2024 Season 2 on at
    RE: How to get Unique Primary Key of the Record (Sales Invoice No.) from Sales Header Table

    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

  • Verified answer
    Govinda Kumar Profile Picture
    Govinda Kumar 2,203 Super User 2024 Season 1 on at
    RE: How to get Unique Primary Key of the Record (Sales Invoice No.) from Sales Header Table

    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

  • Inkey Solutions Profile Picture
    Inkey Solutions 1,654 on at
    RE: How to get Unique Primary Key of the Record (Sales Invoice No.) from Sales Header Table

    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.

  • Inkey Solutions Profile Picture
    Inkey Solutions 1,654 on at
    RE: How to get Unique Primary Key of the Record (Sales Invoice No.) from Sales Header Table

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

  • Inkey Solutions Profile Picture
    Inkey Solutions 1,654 on at
    RE: How to get Unique Primary Key of the Record (Sales Invoice No.) from Sales Header Table

    Codeunit1.png

    pastedimage1684212376267v1.pngCodeunit-2.png

    Code Unit

    PageExt1.pngPageExt2.png

    Page Ext

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: How to get Unique Primary Key of the Record (Sales Invoice No.) from Sales Header Table

    Hi,

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

  • Suggested answer
    Govinda Kumar Profile Picture
    Govinda Kumar 2,203 Super User 2024 Season 1 on at
    RE: How to get Unique Primary Key of the Record (Sales Invoice No.) from Sales Header Table

    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

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,219 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans