Create Service Header when posting a purchase doc.

dkonedkone Member Posts: 59
hi all,

I need to connect purchase invoice to Service Management. I want that when a purchase is posted NAV creates and post and Service Order so it will increase the cost for a service contract.

I will modify purchase line and G/L entry to store a "Contract No." just like "Job No."

After that, i know what to do but i don't know when.

I think there is 3 possiblities :
1- Do it in CU 90 during posting (for each purch line create an service line and post it at the end)
2- After posting from Posted Purchase Line
3- After posting from G/L entry.

IMHO 1 & 2 are (a lot) easier but don't respect the "Nav way" because they read document lines.
Have you any opinion about the right way ?

Thanks for reading this long & boring & not well written post (but i do my best).

dkone.

Answers

  • jlandeenjlandeen Member Posts: 524
    If this is something that is supposed to be tied to purchase posting then CDU 90 is probably the best place to put the code.

    There are some things to watch out for when modifying posting routines that link to other documents and other posting processes.

    1) what happens if there is an error in the 2nd part of the process - in this case what if there is an error when updating the service document, should the posting of the purchase order fail and roll back?
    2) Try to use the posted documents as the source - so determine if the service update should happen during posting of the purchase receipt or the purchase invoice document. This is because an order may only be partially processed at any given time and so any changes to the service documents should reflect data from a posted document (either receipt or invoice)
    3) I would aim for modular and maintable code rather then well performing code in CDU 90 - as both CDU80 and CDU90 are some of the worst spagehetti code I have ever seen and don't really perform very well anyways I would elect to only add a line or 2 of code that executes a new function at the end of CDU 90 - probably just before the commit comand. Like CreateServiceDoc(<Posted Purchase Header Record>) and then do all of your work in this new function. It minimizes the impact to the OnRun trigger in CDU90 and it ensures that upgrading that codeunit will be farily simple and straight forward.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • dkonedkone Member Posts: 59
    Hi Jeff,

    Thank you for your time and your answer .

    1- Fail of service header posting will fail the whole process.
    2- Service orders created by my process must be completely posted. (sorry but i'm not sure i really understand what you wrote).
    3- Thank you for this advice, i'll do a simple call to a new CU. (with 2 functions CreateFromCreditMemo and CreateFromInvoice).

    Regards,

    dkone.
  • jlandeenjlandeen Member Posts: 524
    As far as point 2 goes - the big point I was trying to make is that your new functions CreateFromCreditMemo and CreateFromInvoice
    work with posted table objects. I've worked on one project where a process like this was done and built using the unposted purchase table and it did not work well as they always had to check what had been received...and was was currently being recieved...just a mess.

    So it is much cleaner to use data from the posted side of the transaction that indicates only what happened that transaction. If you fully receive and invoice your document at the same time than it really doesn't matter, there will only be 1 transaction. The problem is if you will ever process partial receipts or invoices.

    On the point about failing on service header posting and rolling all of the way back - this is more difficult and you should be careful as I have seen linked posting processes cause all kinds of grief. When you link your purchase posting to your service order posting remember that there will now be a much longer thread of execution and locking of key tables (i.e. item ledger, no. series, document dimension) and this can badly effect other users - possible "locked by another user" message if it takes too long. You also have to strategically control when commits fire in BOTH posting processes. Another thing to watch out for is to make sure that you don't have any long running processes get kicked off by CDU 90 - like printing a report or other document, make sure commits are called before printing.

    I know there is a lot here - but linking 2 posting processes together is a difficult task and if not done properly can result in poor performance and partially posted documents.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • dkonedkone Member Posts: 59
    Hi Jeff,


    Thanks to you it's done ! I made a new CU called from CU90 that creates the Service Order. The only problem i had was the use of a VALIDATE during header creation (shame on me) making a commit in the middle of the process.
    My process read posted invoice at the end of CU 90 and commit after both docs are posted. My customer doesn't use partial invoicing so it's a bit easier that it could be.

    in case of performance problems, i made this process "batchable" for a night running....

    Thanks again.

    Regards,

    dkone.
  • jlandeenjlandeen Member Posts: 524
    I'm glad to hear that you were able to solve the issue. :D
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
Sign In or Register to comment.