AX7/D365/Operations: Create customer postal address through data entity from .NET console application

Purpose:

The purpose of this document is to demonstrate how we can create customer postal addresses in Dynamics 365 for Finance and Operations using an external .NET console application.

Code:

static void Main(string[] args)
{
      Program program = new Program();
      Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute);
      var context = new Resources(oDataUri);

      context.SendingRequest2 += new EventHandler(delegate (object sender, SendingRequest2EventArgs e)
      {
          var authenticationHeader = OAuthHelper.GetAuthenticationHeader(useWebAppAuthentication: true);
          e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader);
      });

      program.testCustomerAddressCreate(context);
}
public void testCustomerAddressCreate(Resources _context)
{
      DataServiceCollection dataServiceCollection = new DataServiceCollection(_context);
      CustomerPostalAddress customerPostalAddress = new CustomerPostalAddress();

      dataServiceCollection.Add(customerPostalAddress);

      customerPostalAddress.CustomerLegalEntityId = "CPL";
      customerPostalAddress.CustomerAccountNumber = "C0000010";
      customerPostalAddress.AddressDescription = "Test address from OData 44.";
      customerPostalAddress.IsRoleBusiness = NoYes.Yes;
      customerPostalAddress.IsPostalAddress = NoYes.Yes;
      customerPostalAddress.AddressLocationRoles = "Address role";
      customerPostalAddress.AddressCountryRegionId = "AUS";
      customerPostalAddress.AddressZipCode = "2151";
      customerPostalAddress.AddressCity = "NORTH ROCKS";
      customerPostalAddress.AddressState = "NSW";

      DataServiceResponse response = null;

      try
      {
          response = _context.SaveChanges(SaveChangesOptions.PostOnlySetProperties);
      }
      catch (Exception ex)
      {
          Console.WriteLine(ex.Message + ex.InnerException);
      }

      Console.ReadLine();
}
Advertisements

AX7/D365/Operations: Enable/Disable form control in X++

Purpose:

The purpose of this document is to demonstrate how we can enable/disable a form control in X++ based on a business logic.

Product:

Dynamics 365 for Finance and Operations, Platform Update 9.

Development approach:

Customization through extension.

Development:

  1. Create a post event handler of a standard form method enabling/disabling the form controls. In this case, we are creating a post event handler of a standard method setFieldAccessHeader of SalesQuotationProjTable form.
  2. Please find the event handler method definition as follows.
[PostHandlerFor(formStr(SalesQuotationProjTable), formMethodStr(SalesQuotationProjTable, setFieldAccessHeader))]
public static void SalesQuotationProjTable_Post_setFieldAccessHeader(XppPrePostArgs args)
{
    FormRun             sender = args.getThis();
    FormDataSource      salesQuotationTable_ds;
    SalesQuotationTable salesQuotationTable;

    salesQuotationTable_ds = sender.dataSource(1);
    salesQuotationTable = salesQuotationTable_ds.cursor();

    sender.control(sender.controlId(formControlStr(SalesQuotationProjTable, DeviceUsageGroup))).enabled((salesQuotationTable.AMDeviceId) ? true : false);
}