27 Feb’17

Dynamics 365, EnterpriseCreate Service Order from Sales Order using X++

In this blog article, we will see how we can create Service Order from Sales Order using X++ in Dynamics 365 Operations. I have created a button in Sales Order form which will run a class (MenuItem – Action) to create Service Order Header.

Create a new Class:

class CFSServiceOrderCreateFromSalesOrder
    SMAServiceOrderTable serviceOrderTable;
    SMAServiceOrderLine serviceOrderLine;
    SMAserviceTaskRelation serviceTaskRelation;
    SalesTable salesTable;

Create a main method:

public static void main(Args _args)
        Args serviceOrderTableArgs = new Args();
        CFSServiceOrderCreateFromSalesOrder serviceOrderCreateFromSalesOrder = CFSServiceOrderCreateFromSalesOrder::construct();               

        //Call to method createSMAServiceOrder() for Service Order Header creation
        serviceOrderTable = serviceOrderCreateFromSalesOrder.createSMAServiceOrder(_args.record());

        //Infolog to display service order id if service order created else failure message
        info(strFmt("ServiceOrderHeader created with ID: %1", serviceOrderTable.ServiceOrderId));
        info("ServiceOrderHeader creation failed");

Create SMAServiceOrder() method: This method is used to create a Service Order header record.

public SMAServiceOrderTable createSMAServiceOrder(SalesLine _salesLine)
        //initialize SMAServiceOrderTable

        //Initialize Service Order ID
        NumberSeq NumberSeq;
        NumberSeq = NumberSeq::newGetNum(SMAParameters::numRefServiceOrderId(),true);

        serviceOrderTable.ServiceOrderId = NumberSeq.num();

        serviceOrderTable.CustAccount = _salesLine.custAccount;

        serviceOrderTable.ProjId = _salesLine.ProjID;
        //display Customer Name as Service Order Description
        serviceOrderTable.Description = CustTable::find(_salesLine.CustAccount).name(); 
        //insert Service Address

        return serviceOrderTable;

So, this will create a Service Order Header from Sales Order. Let me know your reviews. I will soon come up with more articles, as I further explore D365 Operations.


Written by

Team Member


Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.

Want to streamline your business processes?

  • This field is for validation purposes and should be left unchanged.

Recent Articles

  • Managing mailbox through Email Archiving

    20 March’ 2018

    Introduction: Email can fill your Outlook Inbox quickly – new messages, replies, and forwards. Before you know it, yo...

    Read more
  • Workaround to Report.SAVEASPDF in NAV 2018

    20 March’ 2018

    Objective: In NAV 2017 Emailing the PDF by running the report using Report.SAVEASPDF is now not allowed in NAV 2018. Th...

    Read more
  • Dynamics 365 Client Diagnostics

    15 March’ 2018

    Main cause of Performance Issues: Bandwidth and latency are the primary characteristics which affects the performance o...

    Read more
  • Closing Blind Shift in MPOS and CPOS in Dynamics 365 for Retail

    15 March’ 2018

    Manual For closing Blind shift in POS: Blind shifts terminate the currently ongoing shift and when logged in a new shif...

    Read more
  • Persistent Filters in the Power BI Service

    13 March’ 2018

    Introduction: The feature is finally release, and it is power BI has announced general availability of persistent filt...

    Read more