Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 72043

Extract Metadata Properties of Data Entity Extension

$
0
0

Hi All,

using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.ExcelPackage;
using OfficeOpenXml.ExcelRange;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
class RunnableClass7Modified
{


    public static void main(Args _args)
    {
        DocuFileSaveResult          saveResult = DocuFileSave::promptForSaveLocation("@ApplicationPlatform:OfficeDefaultWorkbookFileName","xlsx", null, "AMDeviceModelCodeEntity - Export excel file");
        container                   headerContainer = ['Field Name', 'Help Text', 'Label', 'Mandatory', 'String Size', 'Computed Field'];
        if (saveResult&& saveResult.parmAction() != DocuFileSaveAction::Cancel)
        {
            saveResult.parmOpenParameters('web=1');
            saveResult.parmOpenInNewWindow(false);



            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();



            using (var package = new OfficeOpenXml.ExcelPackage(memoryStream))
            {
                var currentRow          = 1;
                var worksheets          = package.get_Workbook().get_Worksheets();
                var worksheet           = worksheets.Add('Sheet1');
                var cells               = worksheet.get_Cells();



                OfficeOpenXml.ExcelRange cell;



                for (int i=1; i<=conLen(headerContainer); i++)
                {
                    cell  = cells.get_Item(currentRow, i);
                    cell.set_Value(conPeek(headerContainer, i));
                    cell  = null;
                }



                var     axDataEntity            = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetDataEntityView('AMCaseTableEntity');
                var     dataEntityFields        = axDataEntity.Fields;
                var     dataEntityStagingTable  = axDataEntity.DataManagementStagingTable;
                //gets the tableid for the staging table of the data entity
                int     axTableId               = tableName2Id(dataEntityStagingTable);



                System.Collections.IEnumerator defEnum = dataEntityFields.GetEnumerator();



                while (defEnum.MoveNext())
                {
                    //info(strFmt("Staging Table for Entity: %1", dataEntityStagingTable));
                    //setPrefix("Field Looping");

                    

                    Microsoft.Dynamics.AX.Metadata.MetaModel.AxDataEntityViewField          axTableField    = defEnum.Current;
                    //Microsoft.Dynamics.AX.Metadata.MetaModel.AxDataEntityViewMappedField    axTableMapField = defEnum.Current;


                    int x;
                    

                    DictDataEntity dataEntity = new DictDataEntity(tableNum(AMCaseTableEntity));
                    DictField entityField1 = new DictField(axTableId, fieldName2Id(axTableId, axTableField.Name));
                    DictDataEntityField entityField = new DictDataEntityField(tableNum(AMCaseTableEntity),dataEntity.fieldCnt2Id(x));
                    int cnt   = dataEntity.fieldCnt();

                    //for ( x=1; x<=cnt; x++)
                    //{
                        if(entityField1 )
                        {
                            if(entityField.accessModifier() == FieldAccessModifier::Public)
                        {
                            currentRow ++;



                            cell = null;
                            cell = cells.get_Item(currentRow, 1);
                            cell.set_Value(axTableField.Name);



                            cell = null;
                            cell = cells.get_Item(currentRow, 2);
                            cell.set_Value(entityField1.help());



                            cell = null;
                            cell = cells.get_Item(currentRow, 3);
                            cell.set_Value(entityField1.label());



                            cell = null;
                            cell = cells.get_Item(currentRow, 4);
                            cell.set_Value(entityField.mandatory());



                            cell = null;
                            cell = cells.get_Item(currentRow, 5);
                            cell.set_Value(entityField1.stringLen());


                            cell = null;
                            cell = cells.get_Item(currentRow, 6);
                            cell.set_Value(entityField.IsComputedField());
                        }
                        }
                    //}
                }
                
                package.Save();
            }



            memoryStream.Seek(0, System.IO.SeekOrigin::Begin);



            DocuFileSave::processSaveResult(memoryStream, saveResult);
        }
    }

}

I tried to extract metadata properties of data entity field and extract into excel.

The problem is, i cant extract from data entity extension and got this error.





Viewing all articles
Browse latest Browse all 72043

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>