如何获取AOT对象(例如表)属于ax7中的模型?

时间:2017-08-09 18:29:20

标签: axapta x++ dynamics-ax7

假设我需要- hosts: load-balancer-host tasks: - name: print debug message debug: msg: "this play is for gathering facts on the LB" - name: A play hosts: workers tasks: - name: Look for text pattern in delegated host delegate_to: load-balancer-host find: paths: "{{ hostvars['load-balancer-host'].ansible_env.ENVIRONMENT_VARIABLE }}/subdir" file_type: file patterns: file.pattern contains: 'text pattern' register: aVariable 属于AOT objects

  • 例如表格对象
  • 我需要modelTables
  • 结果对象可以是Table ExtensionstreeNode

问题:如何从模型中获取AOT对象...

  1. X ++?
  2. T-SQL?
  3. C#代码?
  4. 感谢。

    <小时/> 例如:模型名称为DictTable。我可以使用Visual Studio获取对象。如何从x ++,t-sql,c#?

    获取此对象

    enter image description here

    <小时/> 我目前的x ++代码。太可怕了。

    Fleet Management Extension

1 个答案:

答案 0 :(得分:1)

X ++:https://gist.github.com/mazzy-ax/4d4d06ec2fddd885b67527623467aee8

class Tables
{
    public static void Main(Args _args)
    {
        str aosServiceBin = 'C:\AOSService\webroot\bin';
        str packageDir = 'C:\AOSService\PackagesLocalDirectory';

        //or
        var environment = Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory::GetApplicationEnvironment();
        packageDir = environment.get_Aos().get_PackageDirectory();

        // it's kind of magic
        var runtimeProviderConfiguration = New Microsoft.Dynamics.AX.Metadata.Storage.Runtime.RuntimeProviderConfiguration(packageDir);
        var metadataProviderFactory =  New Microsoft.Dynamics.AX.Metadata.Storage.MetadataProviderFactory();
        var provider = metadataProviderFactory.CreateRuntimeProvider(runtimeProviderConfiguration);

        // object names
        print provider.Tables.ListObjectsForModel('FleetManagement');
        print provider.Tables.ListObjectsForModel('FleetManagementExtension');
        print provider.TableExtensions.ListObjectsForModel('FleetManagement');
        print provider.TableExtensions.ListObjectsForModel('FleetManagementExtension');

        // single object by name
        var custTransMetaData = provider.Tables.Read('CustTrans');
    }

}

Powershell脚本:https://gist.github.com/mazzy-ax/292f2ce1a8e79c39d1fc753bfca9c529

$aosServiceBin = 'C:\AOSService\webroot\bin'
$packageDir = 'C:\AOSService\PackagesLocalDirectory'

# or 
add-type -path (Join-Path $aosServiceBin 'Microsoft.Dynamics.ApplicationPlatform.Environment.dll')
$environment = [Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory]::GetApplicationEnvironment()
$packageDir = $environment.get_Aos().get_PackageDirectory()

# it's kind of magic
add-type -path (Join-Path $aosServiceBin 'Microsoft.Dynamics.Ax.Metadata.Storage.dll')
$runtimeProviderConfiguration = New-Object Microsoft.Dynamics.AX.Metadata.Storage.Runtime.RuntimeProviderConfiguration $packageDir
$metadataProviderFactory =  New-Object Microsoft.Dynamics.AX.Metadata.Storage.MetadataProviderFactory
$provider = $metadataProviderFactory.CreateRuntimeProvider($runtimeProviderConfiguration)

# object names
$provider.Tables.ListObjectsForModel('FleetManagement').count
$provider.Tables.ListObjectsForModel('FleetManagementExtension').count
$provider.TableExtensions.ListObjectsForModel('FleetManagement').count
$provider.TableExtensions.ListObjectsForModel('FleetManagementExtension').count

# single object by name
$provider.Tables.Read('CustTrans')

C#,T-SQL可以在他自己的图像中创建。