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
0
Comments
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
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..
Ally
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 Number 3) Copy the lines and values from header
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.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Thanks once again.. I took your advice and applied the codes.. and it's now working fine..
Ally
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..