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

Notifications

Announcements

Community site session details

Community site session details

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

Job Planning lines while creating Sales Invoice from Job planning Lines

(0) ShareShare
ReportReport
Posted on by 980

Hi,

While creating Sales Invoice by transferring lines to Sales invoice from Job Planning Lines The requirement is that There is a custom field Customer PO

pastedimage1610490207476v1.png

while the user will go to transfer a line if the line has a customer Po different from the previous lines there should be an error and not allow to transfer lines.

I have created a procedure based on an event CreateLines

My code is as follows:

[EventSubscriber(ObjectType::CodeUnit1002'OnBeforeCreateSalesInvoiceLines''', false, false)]
    procedure OnBeforeCreateSalesInvoiceLines(var JobPlanningLine: Record "Job Planning Line";
       InvoiceNo: Code[20];
       NewInvoice: Boolean;
       PostingDate: Date;
       CreditMemo: Boolean)

    var
        customerPO: Text[50];
        customerPON: Text[50];
    begin

        JobPlanningLine.Init();
        JobPlanningLine.FindFirst;
        customerPO := JobPlanningLine."WCI Description 2";
        Message('1' + customerPO);


    end;



but the problem is the comparison of the current record value with the previous rows customer Po is not happening.
Please help
Regards,
Indira
I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,251 Super User 2025 Season 2 on at

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Job Create-Invoice", 'OnBeforeCreateSalesInvoiceLines', '', true, true)]
        local procedure "Job Create-Invoice_OnBeforeCreateSalesInvoiceLines" (var JobPlanningLine: Record "Job Planning Line"; InvoiceNo: Code[20]; NewInvoice: Boolean;
    		PostingDate: Date; 	CreditMemo: Boolean     )
    
        var 
            JobPlanningLine2: Record "Job Planning Line";   
            CustomerPONo: Code[20];
        begin
            JobPlanningLine2.Copy(JobPlanningLine);
            If JobPlanningLine2.FindSet() then 
                repeat
                    if CustomerPONo = '' then 
                        CustomerPONo := JobPlanningLine2."Customer PO No."
                    else
                        if CustomerPONo <> JobPlanningLine2."Customer PO No." then
                            Error('Customer PO No. is not matching');  
    
                until JobPlanningLine2.Next() = 0
    
        end;
    

    You need to add code something like above.

  • Indira88 Profile Picture
    980 on at

    Dear Kulla,

    Thank you for the help! but the code seems to work when 2 or more lines are being invoiced together when only single line is invoiced the customer po is comparing with itself and hence not going in the condition .I need to compare the current record po with the prev record po to mitigate this how can this b achieved.

    Regards,

    Indira

  • Verified answer
    Suresh Kulla Profile Picture
    50,251 Super User 2025 Season 2 on at

    You don't need to compare with previous records your goal is to have all of the same customer PO no. so you take the first PO no. and then compare the rest if they have the same value or not.

  • Indira88 Profile Picture
    980 on at

    Thanks Kulla,it helped me compare the po s .

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

News and Announcements

Season of Giving Solutions is Here!

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 1,594

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,594

#3
YUN ZHU Profile Picture

YUN ZHU 748 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans