From 084e56669f3cf2787f5b7b92b7219fd65e2c7fd6 Mon Sep 17 00:00:00 2001
From: Caleb Blanchard <caleb.blanchard@arbelatech.com>
Date: Fri, 26 Aug 2022 11:48:48 -0400
Subject: [PATCH] Add the object ID to objects that have an ID (not just
 tables), and add it to be filterable

---
 .../AxClass/ARBAOTBrowserHelper.xml           |  59 ++++++++++
 .../AxClass/ARBAOTObjectPopulateService.xml   |   7 ++
 .../AOTBrowser/AxEdt/ARBObjectId.xml          |  10 ++
 .../AOTBrowser/AxForm/ARBAOTBrowser.xml       |  21 +++-
 .../en-US/AOTBrowser.en-US.label.txt          | 102 +++++++++---------
 .../AOTBrowser/AxTable/ARBAOTObjects.xml      |   5 +
 .../AOTBrowser/AOTBrowser/AOTBrowser.rnrproj  |  11 ++
 7 files changed, 161 insertions(+), 54 deletions(-)
 create mode 100644 Metadata/AOTBrowser/AOTBrowser/AxClass/ARBAOTBrowserHelper.xml
 create mode 100644 Metadata/AOTBrowser/AOTBrowser/AxEdt/ARBObjectId.xml

diff --git a/Metadata/AOTBrowser/AOTBrowser/AxClass/ARBAOTBrowserHelper.xml b/Metadata/AOTBrowser/AOTBrowser/AxClass/ARBAOTBrowserHelper.xml
new file mode 100644
index 0000000..a3f62e7
--- /dev/null
+++ b/Metadata/AOTBrowser/AOTBrowser/AxClass/ARBAOTBrowserHelper.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<AxClass xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
+	<Name>ARBAOTBrowserHelper</Name>
+	<SourceCode>
+		<Declaration><![CDATA[
+using Microsoft.Dynamics.AX.Metadata.MetaModel;
+using Microsoft.Dynamics.AX.Metadata.Core.MetaModel;
+
+public final class ARBAOTBrowserHelper
+{
+}
+]]></Declaration>
+		<Methods>
+			<Method>
+				<Name>getObjectIdByName</Name>
+				<Source><![CDATA[
+    public static int getObjectIdByName(anytype _object)
+    {
+        INamedObject namedObject = _object as INamedObject;
+        if (namedObject == null)
+        {
+            return 0;
+        }
+        str objectName = namedObject.Name;
+        int objectId;
+
+        switch (true)
+        {
+            case _object is AxTable:
+            case _object is AxView:
+            case _object is AxDataEntityView:
+                objectId = tableName2Id(objectName);
+                break;
+
+            case _object is AxEnum:
+                objectId = enumName2Id(objectName);
+                break;
+
+            case _object is AxClass:
+                objectId = className2Id(objectName);
+                break;
+
+            case _object is AxEdt:
+                objectId = extendedTypeName2Id(objectName);
+                break;
+
+            case _object is AxConfigurationKey:
+                objectId = configurationKeyName2Id(objectName);
+                break;
+        }
+
+        return objectId;
+    }
+
+]]></Source>
+			</Method>
+		</Methods>
+	</SourceCode>
+</AxClass>
\ No newline at end of file
diff --git a/Metadata/AOTBrowser/AOTBrowser/AxClass/ARBAOTObjectPopulateService.xml b/Metadata/AOTBrowser/AOTBrowser/AxClass/ARBAOTObjectPopulateService.xml
index 7975551..49a4630 100644
--- a/Metadata/AOTBrowser/AOTBrowser/AxClass/ARBAOTObjectPopulateService.xml
+++ b/Metadata/AOTBrowser/AOTBrowser/AxClass/ARBAOTObjectPopulateService.xml
@@ -38,6 +38,7 @@ class ARBAOTObjectPopulateService extends SysOperationServiceBase
             aotObjects.Name = table.Name;
             aotObjects.Label = SysLabel::labelId2String2(table.Label);
             aotObjects.Type = ARBAOTObjectType::Table;
+            aotObjects.ObjectId = tableName2Id(table.Name);
             aotObjectsInsertList.add(aotObjects);
         }
 
@@ -51,6 +52,7 @@ class ARBAOTObjectPopulateService extends SysOperationServiceBase
             aotObjects.Name = view.Name;
             aotObjects.Label = SysLabel::labelId2String2(view.Label);
             aotObjects.Type = ARBAOTObjectType::View;
+            aotObjects.ObjectId = tableName2Id(view.Name);
             aotObjectsInsertList.add(aotObjects);
 
         }
@@ -65,6 +67,7 @@ class ARBAOTObjectPopulateService extends SysOperationServiceBase
             aotObjects.Name = enum.Name;
             aotObjects.Label = SysLabel::labelId2String2(enum.Label);
             aotObjects.Type = ARBAOTObjectType::BaseEnum;
+            aotObjects.ObjectId = enumName2Id(enum.Name);
             aotObjectsInsertList.add(aotObjects);
 
         }
@@ -79,6 +82,7 @@ class ARBAOTObjectPopulateService extends SysOperationServiceBase
             aotObjects.Name = edt.Name;
             aotObjects.Label = SysLabel::labelId2String2(edt.Label);
             aotObjects.Type = ARBAOTObjectType::ExtendedDataType;
+            aotObjects.ObjectId = extendedtypeName2Id(edt.Name);
             aotObjectsInsertList.add(aotObjects);
 
         }
@@ -93,6 +97,7 @@ class ARBAOTObjectPopulateService extends SysOperationServiceBase
             aotObjects.Name = dataEntityView.Name;
             aotObjects.Label = SysLabel::labelId2String2(dataEntityView.Label);
             aotObjects.Type = ARBAOTObjectType::DataEntity;
+            aotObjects.ObjectId = tableName2Id(dataEntityView.Name);
             aotObjectsInsertList.add(aotObjects);
 
         }
@@ -121,6 +126,7 @@ class ARBAOTObjectPopulateService extends SysOperationServiceBase
             aotObjects.Name = aotClass.Name;
             //aotObjects.Label = SysLabel::labelId2String2(aotClass.Label);
             aotObjects.Type = ARBAOTObjectType::Class;
+            aotObjects.ObjectId = className2Id(aotClass.Name);
             aotObjectsInsertList.add(aotObjects);
         }
 
@@ -452,6 +458,7 @@ class ARBAOTObjectPopulateService extends SysOperationServiceBase
             aotObjects.Name = object.Name;
             aotObjects.Label = SysLabel::labelId2String2(object.Label);
             aotObjects.Type = ARBAOTObjectType::ConfigKey;
+            aotObjects.ObjectId = configurationKeyName2Id(object.Name);
             aotObjectsInsertList.add(aotObjects);
         }
 
diff --git a/Metadata/AOTBrowser/AOTBrowser/AxEdt/ARBObjectId.xml b/Metadata/AOTBrowser/AOTBrowser/AxEdt/ARBObjectId.xml
new file mode 100644
index 0000000..a579f3b
--- /dev/null
+++ b/Metadata/AOTBrowser/AOTBrowser/AxEdt/ARBObjectId.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<AxEdt xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns=""
+	i:type="AxEdtInt">
+	<Name>ARBObjectId</Name>
+	<Label>@AOTBrowser:ObjectId</Label>
+	<ArrayElements />
+	<Relations />
+	<TableReferences />
+	<ShowZero>No</ShowZero>
+</AxEdt>
\ No newline at end of file
diff --git a/Metadata/AOTBrowser/AOTBrowser/AxForm/ARBAOTBrowser.xml b/Metadata/AOTBrowser/AOTBrowser/AxForm/ARBAOTBrowser.xml
index 4781cbb..c782f46 100644
--- a/Metadata/AOTBrowser/AOTBrowser/AxForm/ARBAOTBrowser.xml
+++ b/Metadata/AOTBrowser/AOTBrowser/AxForm/ARBAOTBrowser.xml
@@ -442,15 +442,16 @@ public class ARBAOTBrowser extends FormRun
                     object = _object;
                 }
 
-                if (object is AxTable)
+                int objectId = ARBAOTBrowserHelper::getObjectIdByName(object);
+                if (objectId)
                 {
-                    AxTable table = object as AxTable;
                     ARBAOTObjectProperties.clear();
                     ARBAOTObjectProperties.Name = '_Id';
-                    ARBAOTObjectProperties.Value = int2Str(tableName2Id(table.Name));
+                    ARBAOTObjectProperties.Value = int2Str(objectId);
                     ARBAOTObjectProperties.insert();
                 }
-                else if (object is AxTableField)
+
+                if (object is AxTableField)
                 {
                     anytype parent = ObjectTree.getItem(ObjectTree.getRoot()).data();
                     ARBObjectModification objectMod = parent as ARBObjectModification;
@@ -1267,6 +1268,9 @@ public class ARBAOTBrowser extends FormRun
 				<AxFormDataSourceField>
 					<DataField>Name</DataField>
 				</AxFormDataSourceField>
+				<AxFormDataSourceField>
+					<DataField>ObjectId</DataField>
+				</AxFormDataSourceField>
 				<AxFormDataSourceField>
 					<DataField>Partition</DataField>
 				</AxFormDataSourceField>
@@ -1725,6 +1729,15 @@ public class ARBAOTBrowser extends FormRun
 								<DataSource>ARBAOTObjects</DataSource>
 								<Items />
 							</AxFormControl>
+							<AxFormControl xmlns=""
+								i:type="AxFormIntegerControl">
+								<Name>ARBAOTObjects_ObjectId</Name>
+								<Type>Integer</Type>
+								<FormControlExtension
+									i:nil="true" />
+								<DataField>ObjectId</DataField>
+								<DataSource>ARBAOTObjects</DataSource>
+							</AxFormControl>
 						</Controls>
 						<MultiSelect>No</MultiSelect>
 						<ShowRowLabels>No</ShowRowLabels>
diff --git a/Metadata/AOTBrowser/AOTBrowser/AxLabelFile/LabelResources/en-US/AOTBrowser.en-US.label.txt b/Metadata/AOTBrowser/AOTBrowser/AxLabelFile/LabelResources/en-US/AOTBrowser.en-US.label.txt
index fbbd785..21f1e1d 100644
--- a/Metadata/AOTBrowser/AOTBrowser/AxLabelFile/LabelResources/en-US/AOTBrowser.en-US.label.txt
+++ b/Metadata/AOTBrowser/AOTBrowser/AxLabelFile/LabelResources/en-US/AOTBrowser.en-US.label.txt
@@ -1,97 +1,99 @@
-NewLabel0=Label files created on 12/04/2019 20:20:46 for label file Id AOTBrowser and language en-US
- ;Label file comment - see above label
-CompositeDataEntities=Composite data entity
+AggregateDataEntity=Aggregate data entity
  ;ARB_AOTBrowser
-Maps=Map
+AOTBrowser=AOT browser
  ;ARB_AOTBrowser
-Macros=Macro
+AOTBrowserMaintain=Maintain AOT browser
  ;ARB_AOTBrowser
-Tiles=Tile
+AOTBrowserUser=AOT browser user
  ;ARB_AOTBrowser
-Menus=Menu
+AOTObjectProperties=AOT object properties
  ;ARB_AOTBrowser
-AOTBrowser=AOT browser
+AOTObjectPropertiesDevDoc=Holds the properties for the AOT object
  ;ARB_AOTBrowser
-BaseEnum=Base enum
+AOTObjects=AOT objects
  ;ARB_AOTBrowser
-MenuItemDisplay=Display menu item
+AOTObjectsDevDoc=List of objects in the application object tree
  ;ARB_AOTBrowser
-MenuItemOutput=Output menu item
+BaseEnum=Base enum
  ;ARB_AOTBrowser
-MenuItemAction=Action menu item
+CompositeDataEntities=Composite data entity
  ;ARB_AOTBrowser
-SecurityRole=Security role
+ConfigKey=Configuration key
  ;ARB_AOTBrowser
-SecurityDuty=Security duty
+ConfigKeyGroup=Configuration key group
  ;ARB_AOTBrowser
-SecurityPrivilege=Security privilege
+LicenseCode=License code
  ;ARB_AOTBrowser
-PopulateAOTObjectTable=AOTBrowser - Populate AOT object table
+Macros=Macro
  ;ARB_AOTBrowser
-ObjectType=Object type
+Maps=Map
  ;ARB_AOTBrowser
-Object=Object
+MenuItemAction=Action menu item
  ;ARB_AOTBrowser
-OpenInAOTBrowser=Open in AOT browser
+MenuItemDisplay=Display menu item
  ;ARB_AOTBrowser
-AOTObjects=AOT objects
+MenuItemOutput=Output menu item
  ;ARB_AOTBrowser
-AOTObjectsDevDoc=List of objects in the application object tree
+Menus=Menu
  ;ARB_AOTBrowser
-TableStatisticsDevDoc=Statistics about each table in the database
+NewLabel0=Label files created on 12/04/2019 20:20:46 for label file Id AOTBrowser and language en-US
+ ;Label file comment - see above label
+Object=Object
  ;ARB_AOTBrowser
-PropertyValue=Value
+ObjectId=Object id
+ ;AOTBrowser
+ObjectType=Object type
  ;ARB_AOTBrowser
-AOTObjectProperties=AOT object properties
+OpenInAOTBrowser=Open in AOT browser
  ;ARB_AOTBrowser
-AOTObjectPropertiesDevDoc=Holds the properties for the AOT object
+OpenTableBrowserButton=Open table browser
  ;ARB_AOTBrowser
-AggregateDataEntity=Aggregate data entity
+PopulateAOTObjects=Populate AOT objects
  ;ARB_AOTBrowser
-WorkflowCategory=Workflow category
+PopulateAOTObjectTable=AOTBrowser - Populate AOT object table
  ;ARB_AOTBrowser
-WorkflowApproval=Workflow approval
+PropertyValue=Value
  ;ARB_AOTBrowser
-WorkflowTask=Workflow task
+Reference=Reference
  ;ARB_AOTBrowser
-WorkflowAutomatedTask=Workflow automated task
+Report=Report
  ;ARB_AOTBrowser
-WorkflowType=Workflow type
+Resource=Resource
  ;ARB_AOTBrowser
-WorkflowHierarchyAssignmentProvider=Workflow hierarchy assignment provider
+SecurityDuty=Security duty
  ;ARB_AOTBrowser
-WorkflowParticipantAssignmentProvider=Workflow participant assignment provider
+SecurityPrivilege=Security privilege
  ;ARB_AOTBrowser
-WorkflowQueueAssignmentProvider=Workflow queue assignment provider
+SecurityRole=Security role
  ;ARB_AOTBrowser
-WorkflowDueDateCalculationProvider=Workflow due date calculation provider
+Service=Service
  ;ARB_AOTBrowser
-Resource=Resource
+ServiceGroup=Service group
  ;ARB_AOTBrowser
-LicenseCode=License code
+TableStatisticsDevDoc=Statistics about each table in the database
  ;ARB_AOTBrowser
-ConfigKey=Configuration key
+Tiles=Tile
  ;ARB_AOTBrowser
-ConfigKeyGroup=Configuration key group
+ViewCode=View source code
  ;ARB_AOTBrowser
-Reference=Reference
+ViewCodeHelp=Toggles the ability to view the source code. (NOTE: Viewing metadata from 3rd parties provided by deployable package is not supported with this turned on)
+ViewExtensionsInline=Show extensions inline
  ;ARB_AOTBrowser
-Service=Service
+WorkflowApproval=Workflow approval
  ;ARB_AOTBrowser
-ServiceGroup=Service group
+WorkflowAutomatedTask=Workflow automated task
  ;ARB_AOTBrowser
-Report=Report
+WorkflowCategory=Workflow category
  ;ARB_AOTBrowser
-PopulateAOTObjects=Populate AOT objects
+WorkflowDueDateCalculationProvider=Workflow due date calculation provider
  ;ARB_AOTBrowser
-OpenTableBrowserButton=Open table browser
+WorkflowHierarchyAssignmentProvider=Workflow hierarchy assignment provider
  ;ARB_AOTBrowser
-AOTBrowserMaintain=Maintain AOT browser
+WorkflowParticipantAssignmentProvider=Workflow participant assignment provider
  ;ARB_AOTBrowser
-AOTBrowserUser=AOT browser user
+WorkflowQueueAssignmentProvider=Workflow queue assignment provider
  ;ARB_AOTBrowser
-ViewExtensionsInline=Show extensions inline
+WorkflowTask=Workflow task
  ;ARB_AOTBrowser
-ViewCode=View source code
+WorkflowType=Workflow type
  ;ARB_AOTBrowser
-ViewCodeHelp=Toggles the ability to view the source code. (NOTE: Viewing metadata from 3rd parties provided by deployable package is not supported with this turned on)
diff --git a/Metadata/AOTBrowser/AOTBrowser/AxTable/ARBAOTObjects.xml b/Metadata/AOTBrowser/AOTBrowser/AxTable/ARBAOTObjects.xml
index 8e19e95..11ddc3c 100644
--- a/Metadata/AOTBrowser/AOTBrowser/AxTable/ARBAOTObjects.xml
+++ b/Metadata/AOTBrowser/AOTBrowser/AxTable/ARBAOTObjects.xml
@@ -114,6 +114,11 @@ public class ARBAOTObjects extends common
 			<Mandatory>Yes</Mandatory>
 			<EnumType>ARBAOTObjectType</EnumType>
 		</AxTableField>
+		<AxTableField xmlns=""
+			i:type="AxTableFieldInt">
+			<Name>ObjectId</Name>
+			<ExtendedDataType>ARBObjectId</ExtendedDataType>
+		</AxTableField>
 	</Fields>
 	<FullTextIndexes />
 	<Indexes>
diff --git a/Projects/AOTBrowser/AOTBrowser/AOTBrowser.rnrproj b/Projects/AOTBrowser/AOTBrowser/AOTBrowser.rnrproj
index c07d61b..3bad9d7 100644
--- a/Projects/AOTBrowser/AOTBrowser/AOTBrowser.rnrproj
+++ b/Projects/AOTBrowser/AOTBrowser/AOTBrowser.rnrproj
@@ -34,6 +34,7 @@
     <Folder Include="Classes\" />
     <Folder Include="Display Menu Items\" />
     <Folder Include="EDT Enums\" />
+    <Folder Include="EDT Integers\" />
     <Folder Include="Extended Data Types\" />
     <Folder Include="Form Extensions\" />
     <Folder Include="Forms\" />
@@ -56,6 +57,11 @@
       <Name>ARBAOTBrowserConstants</Name>
       <Link>Classes\ARBAOTBrowserConstants</Link>
     </Content>
+    <Content Include="AxClass\ARBAOTBrowserHelper">
+      <SubType>Content</SubType>
+      <Name>ARBAOTBrowserHelper</Name>
+      <Link>Classes\ARBAOTBrowserHelper</Link>
+    </Content>
     <Content Include="AxClass\ARBAOTObjectPopulateController">
       <SubType>Content</SubType>
       <Name>ARBAOTObjectPopulateController</Name>
@@ -136,6 +142,11 @@
       <Name>ARBAOTPropertyValue</Name>
       <Link>Extended Data Types\ARBAOTPropertyValue</Link>
     </Content>
+    <Content Include="AxEdt\ARBObjectId">
+      <SubType>Content</SubType>
+      <Name>ARBObjectId</Name>
+      <Link>EDT Integers\ARBObjectId</Link>
+    </Content>
     <Content Include="AxEnum\ARBAOTObjectType">
       <SubType>Content</SubType>
       <Name>ARBAOTObjectType</Name>