Pages

Wednesday, July 2, 2014

How to: Copy a sales order using SalesCopying class

There are a million code snippets that show you how to create/copy a sales order that work 80% of the time, but often don't account for the many different scenarios from different environments.

This job shows you how to copy a sales order, but more importantly it shows you how to use the SalesCopying class so that you can copy from SalesQuotes, Journals, etc.


static void JobCopySO(Args _args)
{
    SalesTable  salesTable = SalesTable::find('SO000777');
    SalesLine   salesLine;
    SalesTable  salesTableNew;
    SalesOrderCopyingContract contract = SalesOrderCopyingContract::newIsCreditNote(false);
    
    SalesCopying            salesCopying;
    TmpFrmVirtual           tmpFrmVirtualLines;
    TmpFrmVirtual           tmpFrmVirtualHeader;
    
    void writeTmpFrmVirtual(TmpFrmVirtual _tmpFrmVirtual, TableId _tableId, RecId _recId, Num _id, LineNum _lineNum = 0, TransDate _transDate = systemDateGet(), Qty _qty = 0)
    {
        _tmpFrmVirtual.clear();
        _tmpFrmVirtual.TableNum     = _tableId;
        _tmpFrmVirtual.RecordNo     = _recId;
        _tmpFrmVirtual.Id           = _id;
        _tmpFrmVirtual.LineNum      = _lineNum;
        _tmpFrmVirtual.TransDate    = _transDate;
        _tmpFrmVirtual.Qty          = _qty;

        _tmpFrmVirtual.write();
    }
    
    // Create your new sales header
    salesTableNew.SalesId = NumberSeq::newGetNum(SalesParameters::numRefSalesId()).num();
    salesTableNew.initValue();
    salesTableNew.CustAccount = salesTable.CustAccount;
    salesTableNew.initFromCustTable();
    salesTableNew.insert();
    
    // Build header virtual
    writeTmpFrmVirtual(tmpFrmVirtualHeader, salesTable.TableId, salesTable.RecId, salesTable.SalesId);
    
    while select salesLine
        where salesLine.SalesId == salesTable.SalesId
    {
        writeTmpFrmVirtual(tmpFrmVirtualLines, salesLine.TableId, salesLine.RecId, salesLine.SalesId, salesLine.LineNum, systemDateGet(), salesLine.SalesQty);
    }
    
    contract.parmSalesPurchCopy(SalesPurchCopy::CopyAllHeader);
    contract.parmCallingTableSalesId(salesTableNew.SalesId);
    contract.parmTmpFrmVirtualLines(tmpFrmVirtualLines);
    contract.parmTmpFrmVirtualHeader(tmpFrmVirtualHeader);
    contract.parmQtyFactor(1);
    contract.parmRecalculateAmount(NoYes::No);
    contract.parmReverseSign(NoYes::No);
    contract.parmCopyMarkup(NoYes::No);
    contract.parmCopyPrecisely(NoYes::No);
    contract.parmDeleteLines(NoYes::Yes);    
    
    SalesCopying::copyServer(contract.pack(), false);
       
    info(strFmt("Created %1", salesTableNew.SalesId));
}

31 comments:

  1. thanks for the code. Saved me some workhours :)

    ReplyDelete
  2. It's a great opportunity to close the hole and adjust Sales and Marketing for the last time. While you would likely concur, you may not completely comprehend why it's so significant or what can be done.cold call script

    ReplyDelete
  3. Increment acknowledgment of outside sales group with present and potential clients. Think about your business as an expert football crew.how to get past the gatekeeper

    ReplyDelete
  4. Emotionally you need to come from a place of caring and support which will then be reflected in your vocal tone. Sounding judgmental or frustrated could destroy your relationship with your salesperson.fomo tools

    ReplyDelete
  5. This is a splendid website! I"m extremely content with the remarks!. http://home2bis.com/sales-course/

    ReplyDelete
  6. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. order management system

    ReplyDelete
  7. Usually a sales manager is given the number. What they must produce for the year, each quarter, and each month. The goals have been established. Now it's up to the manager to develop a sales business plan to achieve those goals. Business Data

    ReplyDelete
  8. They treat web designer as the addition of their minds. Webdesignlab.be

    ReplyDelete
  9. Direct selling is the direct close to home introduction, exhibit, and sale of items and administrations to customers, generally in their homes or at their positions. In a down economy, direct sales outperform such test. https://www.callcenterdeluxecalls.nl

    ReplyDelete
  10. Facebook permits a business to assemble a brand, draw in clients, get client audits and moment client input. Webdesign

    ReplyDelete
  11. You might need to sell an item, or make an arrangement or even increase data yet the opening ought to mirror the possibilities conditions and ought to be important for a Sales Campaign and not simply conventional hostility. Seoleadgeneration.be

    ReplyDelete
  12. That site traffic will incorporate recurrent customers and web indexes anxious to get to that new substance.SEO Antwerpen

    ReplyDelete
  13. The curriculum for free sales courses usually begins with the sales introduction. This is the process of creating rapport with the prospective customers. קורס מכירות

    ReplyDelete
  14. I will add one admonition to that; there are proficient sales associations whose center business is absolutely selling. F and I resources in Missouri & Kansas

    ReplyDelete
  15. Sales improvement preparing to build your sales abilities is an incredible speculation. However, on the off chance that you simply acquire sales abilities, Wells Fargo ISO Program

    ReplyDelete
  16. A lot of offshore companies have etiquette requirements that their customer support representatives should follow.Customer service call center

    ReplyDelete
  17. The mystery is to begin taking a gander at the sales errands, instead of the sales individuals. North American Bancard ISO Program

    ReplyDelete
  18. How much in dollar esteem is a lot of the expense of running your sales group since that is the amount you are paying for your sales individuals to arrange for who to call. Top 10 Reasons Why You Should Get Salesforce Certified

    ReplyDelete
  19. rapidly coming into recurrent usage of various patients who have observed a significant improvement in their health condition as compared to intake of other conventional medications. coffee roasters sydney

    ReplyDelete
  20. In an all around run, sales centered organization, it is the organization's obligation to characterize the item, characterize the objective market, assemble data on the possibilities, give showcasing backing and the sales individual's must statement and close new clients. posicionamiento web

    ReplyDelete
  21. A salesperson can commit 100% of this chance to the organization. An immediate sales group experiences far less interruptions than a rep sales group. Nonetheless, experienced CEOs and chief groups comprehend that they should completely take a gander at an immediate sales group prior to changing over to it. Direct sales groups are very costly to prepare and uphold. agencia seo

    ReplyDelete
  22. hare it with my other friends as the information is really very useful. Keep sharing your excellent work. dive instructor

    ReplyDelete
  23. The mystery is to begin taking a gander at the sales errands, rather than the sales individuals. Bookkeeping Vaughan

    ReplyDelete
  24. We can be talking millions, in case not huge number of dollars squandered, but rather it happens essentially consistently and in many organizations.túlméretes szállítás Europa-Road Kft.

    ReplyDelete
  25. Thank you so much for the blog post. Thanks Again. Awesome.
    download instagram photos

    ReplyDelete
  26. Your blog have nice information, I got good ideas from this amazing blog. I am always searching like this type blog post. I hope I will see again Commercial Cleaning Perth

    ReplyDelete
  27. just go to see this website daily becauseit presents feature contents, thanks Golden Doodles

    ReplyDelete
  28. Thank you for the knowledge, much appreciated. I run an affiliate website in Norway within the personal finance niche. Do you think online content marketing would be a good strategy for us to implement? For instance, I found an article on Avisen Agder done for Lånesiden. We're considering doing something similar to this, but I'm not sure what to expect when it comes to the ROI.

    ReplyDelete
  29. stumbled upon your internet site and wanted to say that I’ve very favored learning your weblog posts. Any signifies I’ll be subscribing with your feed and I hope you publish once additional soon.Boat Rental Toronto

    ReplyDelete
  30. follow you, the information you bring is very real, reflecting correctly and objectively, it is very useful for society to grow together news

    ReplyDelete