Compartir a través de


Accessing composites

Composites can be displayed as fields on windows, and are accessed as properties of the window or scrolling window they are contained in. Composites can also be used to create variables that are passed as parameters for procedures and functions.

Window fields

Composite fields are accessed as properties of the window or scrolling window they are contained in. For example, to access the Account Number CS field in the Account Maintenance window of Microsoft Dynamics GP, you would use the following syntax:

Dynamics.Forms.GlAccountMaintenance.GlAccountMaintenance.AccountNumberCs

 

Variables

In some cases, you may want to retrieve the value of a composite and use it as a variable in your Visual Studio Tools integration. You can create an instance of the composite, and then set the value of the composite variable.

For example, the following C# code creates an instance of the AccountNumberCs composite, which appears in the Account Maintenance window in Microsoft Dynamics GP. The value of this window field is retrieved. The value of each component is combined into a string and displayed in a message.

// Create an instance of the AccountNumberCs composite
Microsoft.Dexterity.Applications.DynamicsDictionary.AccountNumberCsCompositeData accountNumber = new AccountNumberCsCompositeData();

// Reference the Account Maintenance form
Microsoft.Dexterity.Applications.DynamicsDictionary.GlAccountMaintenanceForm AccountMaintenance = Dynamics.Forms.GlAccountMaintenance;

// Retrieve the Account Number value
accountNumber = AccountMaintenance.GlAccountMaintenance.AccountNumberCs;
string accountNumberString = "";

// Retrieve the individual components
for (int i = 0; i < accountNumber.Length; i++)
{
    accountNumberString = accountNumberString + accountNumber[i] + " ";
}

// Display the account number
System.Windows.Forms.MessageBox.Show("Account number: " + accountNumberString);

Parameters

You can create composite variables and pass them as parameters for procedures and functions. A variable based on the "read-only" composite type must be used as the parameter. To create a "read-only" composite variable, you must first create a variable based on the "data" composite type.

For example, the following C# code creates a variable of the type AccountNumberCompositeData, and sets its component values. A variable of the type AccountNumberCompositeReadOnly is created. Its constructor uses the "data" composite variable to supply the composite's value. The "read-only" version of the composite value is passed as a parameter to the ConvertAcctToAliasStr function.

Microsoft.Dexterity.Applications.DynamicsDictionary.AccountNumberCompositeData accountNumberData = new AccountNumberCompositeData();
accountNumberData[0] = "000";
accountNumberData[1] = "1100";
accountNumberData[2] = "00";
accountNumberData[3] = "";

// Create the read-only composite that is used for the function call
Microsoft.Dexterity.Applications.DynamicsDictionary.AccountNumberCompositeReadOnly accountNumber = new AccountNumberCompositeReadOnly(accountNumberData);

// Convert the account number to its account alias
string alias = Dynamics.Forms.GlAcctBase.Functions.ConvertAcctToAliasStr.Invoke(accountNumber);

// Display the account alias
System.Windows.Forms.MessageBox.Show("Account alias: " + alias);

Components

To access the individual components for most composites, you can use the properties of the composite. The composite will have a property for each component of the composite.

Some composites, such as the AccountNumberComposite, are defined dynamically by Microsoft Dynamics GP. These composites do not have the named properties to access the individual components of the composite. To access components for these composites, you must use the component's index. For instance, the following C# code creates an instance of the AccountNumber composite and sets the value of each component.

AccountNumberCompositeData accountNumberData = new AccountNumberCompositeData();
accountNumberData[0] = "000";
accountNumberData[1] = "1100";
accountNumberData[2] = "00";
accountNumberData[3] = "";