Creating Sales Invoice from Transfer Receipt
ally
Member Posts: 7
Hi there..
I am trying to create a Sales Invoice from a posted Transfer Receipt. I have created a new field in the Transfer Order to capture the Customer No. which will then be passed on to the Transfer Receipt.
I used the Copy Document Management as a reference to create my own codeunit. I was hoping I could use the CreateToHeader to create the Sales Invoice automatically from the Transfer Receipt. However I've not managed to find codes in the standard Navision that automatically creates a document from another document via Copy Document Management.
I have placed the following code to create the Sales Invoice after the Transfer Receipt was created:
CopyTransRcptDoc.SetProperties(TRUE,TRUE,FALSE);
CopyTransRcptDoc.CopySalesInvDoc (TransHeaderReceieved."No.",SalesInvHeader);
FORM.RUN(43,SalesInvHeader);
The parameters for Setproperties are IncludeHeader, CreateToHeader, CreateToLines. However it creates a Sales Quote header instead of to Sales Invoice. I've tried using SetView and it still creates it as a Sales Quote. If I use SetRange, it will prompt an error stating that I cannot write to the table. If anyone could help me figure out how I could make the Sales Header to point to the document type Invoice so that my code can create the document from Transfer Receipt, I would be ever so grateful.
My second problem is once the code to Create the Sales Header has been completed, it will call the function to copy the Sales Lines from the Transfer Receipt Lines. However at this point the system will prompt me an error stating that Sell-To Customer is not assigned to the Sales Header. But I have already copied the Customer No. from the new Cust No. field in my Transfer Receipt header. Help!!
In a nutshell, everytime the Sales Document is created, it is created as a Sales Quote instead of a Sales Invoice and I also cannot proceed to copy the sales line automatically.
I'm also open to other ways I should write my code to achieve this.
Regards,
Ally
I am trying to create a Sales Invoice from a posted Transfer Receipt. I have created a new field in the Transfer Order to capture the Customer No. which will then be passed on to the Transfer Receipt.
I used the Copy Document Management as a reference to create my own codeunit. I was hoping I could use the CreateToHeader to create the Sales Invoice automatically from the Transfer Receipt. However I've not managed to find codes in the standard Navision that automatically creates a document from another document via Copy Document Management.
I have placed the following code to create the Sales Invoice after the Transfer Receipt was created:
CopyTransRcptDoc.SetProperties(TRUE,TRUE,FALSE);
CopyTransRcptDoc.CopySalesInvDoc (TransHeaderReceieved."No.",SalesInvHeader);
FORM.RUN(43,SalesInvHeader);
The parameters for Setproperties are IncludeHeader, CreateToHeader, CreateToLines. However it creates a Sales Quote header instead of to Sales Invoice. I've tried using SetView and it still creates it as a Sales Quote. If I use SetRange, it will prompt an error stating that I cannot write to the table. If anyone could help me figure out how I could make the Sales Header to point to the document type Invoice so that my code can create the document from Transfer Receipt, I would be ever so grateful.
My second problem is once the code to Create the Sales Header has been completed, it will call the function to copy the Sales Lines from the Transfer Receipt Lines. However at this point the system will prompt me an error stating that Sell-To Customer is not assigned to the Sales Header. But I have already copied the Customer No. from the new Cust No. field in my Transfer Receipt header. Help!!
In a nutshell, everytime the Sales Document is created, it is created as a Sales Quote instead of a Sales Invoice and I also cannot proceed to copy the sales line automatically.
I'm also open to other ways I should write my code to achieve this.
Regards,
Ally
0
Comments
-
SalesInvHeader must be existing Header under which the lines will be added. The copy doc functions are working over manually created header with PK filled in (Doc. type and Doc. No)...0
-
Hi Kine,
Thanks for the quick reply!!
You mentioned that
"SalesInvHeader must be existing Header under which the lines will be added."
From my understanding, I thought when the Sales Header was Modified to put in the new copied values from the Transfer Receipt ( in this case would be the Transfer Receipt's new customised field Customer No assigned to the Sales Invoice's Sell-to Customer No.) the record already exists. Could you please ellaborate this further and does this means I have to create the header first, and then go to the Sales Invoice form and use a customised Copy Document form to copy in the Sales Line from the Transfer Receipt Lines? I'm rather confused. :oops:
I added this line of code
SalesInvHeader."Document Type" := SalesInvHeader."Document Type"::Invoice;
to my previous line of codes
CopyTransRcptDoc.SetProperties(TRUE,TRUE,FALSE);
CopyTransRcptDoc.CopySalesInvDoc (TransHeaderReceieved."No.",SalesInvHeader);
FORM.RUN(43,SalesInvHeader);
and now it creates to the Sales Invoice. My question is.. is this safe and proper way to make the Sales Header to point to Document Type::Invoice?
Thanks once again..
Ally0 -
Recap: Which steps are needed to create copy of document in standard Navision?
1) Create Header (F3)
2) Assign new No. (enter on blank No. field) -> In this step the record is inserted into table
3) Call function which will copy the lines and header values from another document
-> result:
If you need do that through C/AL code you need use same approach:
1 and 2) Create Header with new NumberSalesInvHeader.INIT; SalesInvHeader."Type" := SalesInvHeader."Type"::Invoice; SalesInvHeader.VALIDATE("No.",''); SalesInvHeader.INSERT(True);3) Copy the lines and values from headerCopyTransRcptDoc.SetProperties(TRUE,TRUE,FALSE); CopyTransRcptDoc.CopySalesInvDoc(TransHeaderReceieved."No.",SalesInvHeader);
That is all...
The easiest way for "how to do that" is simulating it "by hands" (what you need to do manually) and "simulate" the same things by C/AL code. Do not forget that if you enter something by keyboard it means VALIDATE in code and saving record on form (or modify record) means INSERT(True) or MODIFY(True) in code.0 -
Hi Kine,
Thanks once again.. I took your advice and applied the codes.. and it's now working fine..
Ally0 -
hi,
I am getting an error " The sales invoice line does not exist Identification field & values. Doc no " abc " Line No :"10000"
while doing copy document in Credit memo form. I tried to debug but could not find the link. If any one has solved same issue than plz guide me ..The same error is seen in " Get Posted Document Lines to Reverse" After i select posted sales invoice .
Thanks a lot..0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 328 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
