Exercise - Create an extension by using Chain of Command

Completed

You are a developer that must make a customization to the CustTable insert method. Upon customer creation, if the customer credit rating is less than 200, then the customer should be blocked for all delivery and invoicing. A prompt should appear to alert the person who is entering the customer details.

Before you begin

To get the most benefit from this exercise, we recommend that you have the standard sample data available in finance and operations apps installed by using Lifecycle Services. You will also need a developer environment and trial or permanent license for using Visual Studio.

Create a new project

  1. Open Visual Studio, running as an administrator, and open the File menu.
  2. Select New > Project.
  3. In the New Project dialog box, ensure that Dynamics 365 is selected on the left pane under Templates.
  4. On the middle pane, select Finance Operations.
  5. Name the project ChainOfCommand.
  6. Select OK.
  7. Open the Dynamics 365 menu in the ribbon.
  8. Select Options.
  9. Under the Dynamics 365 node on the left pane, select Projects.
  10. Select the check boxes for Organize projects by element type and Synchronize database on build for newly created project.
  11. Select OK.
  12. In the Solution explorer, right-click your project name and select Properties.
  13. In the properties page, change the Model field to Fleet Management.
  14. Select OK.
  15. Now you need to ensure you have the correct references.
  16. Go to the Dynamics 365 menu.
  17. Select Model management > Update model parameters.
  18. In the Model name dropdown, select Fleet Management.
  19. Select Next.
  20. In the Selected references packages page, ensure Directory and Application Suite are checked.
  21. Once finished, select Finish.

Create an extension of a method in the CustTable class

  1. In the Solution Explorer window, right-click the project ChainOfCommand.
  2. Select Add > New Item.
  3. In the left pane, select Dynamics 365 Items.
  4. Select Class in the middle pane.
  5. Enter CustTable_Extension as the name.
  6. Select Add.
  7. In the CustTable_Extension class, add the following code to set the field Invoicing and Delivery on hold to All and to display a message after the insert.
[ExtensionOf(tableStr(CustTable))]
final class CustTable_Extension
{
    public void insert(DirPartyType _partyType, Name _name,boolean _updateCRM)
   {
        if (str2Int(this.creditRating) < 200)
        {
            this.blocked = CustVendorBlocked::All;
			info("The customer has been placed on hold due to low credit rating. Please review.");
        }
        next insert();       
   } 
}
  1. Save the class.
  2. Build the project.