Modify function in Existing Standard Codeunit 81 "Sales-Post (Yes/No)" in AL.

Ghizlane
Member Posts: 45
Hi All!
Can you please advice how to change/remove code from default codeunit .
let say for my example if i want to remove invoice and ship from codeunit 81 "Sales-Post (Yes/No)" !
Can you please advice how to achieve this from AL ? (Business central)

Can you please advice how to change/remove code from default codeunit .
let say for my example if i want to remove invoice and ship from codeunit 81 "Sales-Post (Yes/No)" !
Can you please advice how to achieve this from AL ? (Business central)

0
Best Answers
-
This is probably in the direction of what you need, now be creative
LOCAL Code(VAR SalesHeader : Record "Sales Header";PostAndSend : Boolean)
HideDialog := FALSE;
IsHandled := FALSE;
DefaultOption := 3;
IF IsHandled THEN
EXIT;
IF NOT HideDialog THEN
IF NOT ConfirmPost(SalesHeader,DefaultOption) THEN
EXIT;
SalesSetup.GET;
IF SalesSetup."Post with Job Queue" AND NOT PostAndSend THEN
SalesPostViaJobQueue.EnqueueSalesDoc(SalesHeader)
ELSE
CODEUNIT.RUN(CODEUNIT::"Sales-Post",SalesHeader);
LOCAL ConfirmPost(VAR SalesHeader : Record "Sales Header";DefaultOption : Integer) : Boolean
IF DefaultOption > 3 THEN
DefaultOption := 3;
IF DefaultOption <= 0 THEN
DefaultOption := 1;
WITH SalesHeader DO BEGIN
CASE "Document Type" OF
"Document Type"::Order:
BEGIN
Selection := STRMENU(ShipInvoiceQst,DefaultOption);
Ship := Selection IN [1,3];
Invoice := Selection IN [2,3];
IF Selection = 0 THEN
EXIT(FALSE);
END;
"Document Type"::"Return Order":
BEGIN
Selection := STRMENU(ReceiveInvoiceQst,DefaultOption);
IF Selection = 0 THEN
EXIT(FALSE);
Receive := Selection IN [1,3];
Invoice := Selection IN [2,3];
END
ELSE
IF NOT ConfirmManagement.ConfirmProcess(
STRSUBSTNO(PostConfirmQst,LOWERCASE(FORMAT("Document Type"))),TRUE)
THEN
EXIT(FALSE);
END;
"Print Posted Documents" := FALSE;
END;
EXIT(TRUE);
5 -
You still have the variables as locals and not as parameters!
It should beMyconfirmPost(VAR SalesHeader : Record "Sales Header";VAR HideDialog : Boolean;VAR IsHandled : Boolean)
5 -
I change the variables as parameters and it does work
But I don't understand why it does work even if the functions doesn't have the same name as codeunit 81(standard) (ConfirmPost;MyConfirmPost)
0
Answers
-
Is you run the eventrecord page and start recording you can see which event you can hook into..
Or read the code in C/SideFor help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.1 -
Create a subscriber on Codeunit 81 OnBeforeConfirmSalesPost which has the parameters:
VAR SalesHeader : Record "Sales Header" <= Set SalesHeader.Ship := TRUE and SalesHeader.Invoice := TRUE;
VAR HideDialog : Boolean <= Set HideDialog := TRUE;
VAR IsHandled : Boolean <= Set IsHandled := TRUE;1 -
Hi Dukmeester
Even if I add this parametres I still have the same dialog
0 -
Hi SanderDk,
I know that I should modify OnBeforeConfirmSalesPost event on Codeunit 81, but I don't know how I can do it .
can you please advice me?0 -
You should add SalesHeader, HideDialog, and so on (check OnBeforeConfirmSalesPost parameters in CU81) as parameters of your Eventsubscriber. And even then, you will only be able to skip the posting, skip the dialog, or fill the default option of the dialog. There will be three options on it if it is shown, I don't see how to change that using AL code. That being said.. set IsHandled to true, and write your own "CU81" that's probably the way to go now.1
-
as you know in business central i can't modify on standard code and there isn't a way to create an extension of codeunit
the solution is created eventsubscriber .
I try to create it but I don't know how can I acces to function on standard codeunit and modify it .
I wanna to remove option ship and invoice
if you have any idea would you help me .
thnx0 -
This is probably in the direction of what you need, now be creative
LOCAL Code(VAR SalesHeader : Record "Sales Header";PostAndSend : Boolean)
HideDialog := FALSE;
IsHandled := FALSE;
DefaultOption := 3;
IF IsHandled THEN
EXIT;
IF NOT HideDialog THEN
IF NOT ConfirmPost(SalesHeader,DefaultOption) THEN
EXIT;
SalesSetup.GET;
IF SalesSetup."Post with Job Queue" AND NOT PostAndSend THEN
SalesPostViaJobQueue.EnqueueSalesDoc(SalesHeader)
ELSE
CODEUNIT.RUN(CODEUNIT::"Sales-Post",SalesHeader);
LOCAL ConfirmPost(VAR SalesHeader : Record "Sales Header";DefaultOption : Integer) : Boolean
IF DefaultOption > 3 THEN
DefaultOption := 3;
IF DefaultOption <= 0 THEN
DefaultOption := 1;
WITH SalesHeader DO BEGIN
CASE "Document Type" OF
"Document Type"::Order:
BEGIN
Selection := STRMENU(ShipInvoiceQst,DefaultOption);
Ship := Selection IN [1,3];
Invoice := Selection IN [2,3];
IF Selection = 0 THEN
EXIT(FALSE);
END;
"Document Type"::"Return Order":
BEGIN
Selection := STRMENU(ReceiveInvoiceQst,DefaultOption);
IF Selection = 0 THEN
EXIT(FALSE);
Receive := Selection IN [1,3];
Invoice := Selection IN [2,3];
END
ELSE
IF NOT ConfirmManagement.ConfirmProcess(
STRSUBSTNO(PostConfirmQst,LOWERCASE(FORMAT("Document Type"))),TRUE)
THEN
EXIT(FALSE);
END;
"Print Posted Documents" := FALSE;
END;
EXIT(TRUE);
5 -
You defined the SalesHeader, HideDialog, IsHandled variables as locals instead of parameters.
All as VAR ofcourse.1 -
I try it but I get the same dialog box .0
-
if you used VAR SalesHeader;VAR HideDialog;VAR IsHandled then I have no clue why it would not work. Can only think the extension was not properly activated or something. Run with debug and put a breakpoint on the first line in the extension.
1 -
If you run it with IsHandled := true, nothing wil happen, CU81 is exited.
If you run it with HideDialog := true, no dialog wil appear.
You cannot change the appearance of dialog with this.
So, set Ishandled to true, and write own code. This is the only way to change appearance.0 -
Please try the my code
1 -
Hi MesutG,
I try the code that you write me,
this is result ,
it showed two dialog box.
it's possible hide the dialog box that contain (ship invoice ship and invoice)??
best regards
0 -
You still have the variables as locals and not as parameters!
It should beMyconfirmPost(VAR SalesHeader : Record "Sales Header";VAR HideDialog : Boolean;VAR IsHandled : Boolean)
5 -
[Topic moved from 'NAV Courses, Exams & Certification' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!1 -
I change the variables as parameters and it does work
But I don't understand why it does work even if the functions doesn't have the same name as codeunit 81(standard) (ConfirmPost;MyConfirmPost)
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions