Jet another small X++ job: This job shows a list of child classes per parent class.
If you want so see the parent-child relationship in AX2012, the best way is to Right click on the class > Add-ons > Type hierarchy browser.
The Type hierarchy browser shows the relationships between parent and child classes as well as the methods in each class. While this is great functionality I use regularly, I found it a bit difficult to see which child classes inherit or override a particular parent method.
I wanted to add a parameter variable to the header of one of the invent movement child methods. Parent and child methods in X++ must have exactly the same parameters. This means if you want to add a parameter to a child method you must also add it to the parent method and to all the other children that over rides that particular method. The list below shows me how many child classes I need to modify if I want to add a parameter to one child method.
For example, the InventMovement class has 85 child classes. Only 24 of those children overrides the method “DefaultDimension”. If you want to pass an extra boolean parameter to any of those 24 “DefaultDimension” methods, you have to add it to the definition of all 24 methods and to the parent.
This job creates a list of the 24 classes that overrides the “DefaultDimension” method in the InventMovement class.
My first instinct was to use the SysDictClass’s hasObjectMethod method, but since the method is available on all children through inheritance, it always evaluate to true.
I wrote a job today to create a list of fields in a table and each field’s data type. You specify a table name in the variables, and it he job exports a list of non-system fields in the format: “Displayed name” (label), “Technical Name” and “Data Type” to CSV file.
Notice (line 50 – 70) that it lists the possible enum values for enum fields. It also adds the string length in brackets for string fields.
The cross reference on the environment I am currently working on is not up to date. I used this job to find all the table fields that use this extended data type, similar to what the standard cross reference function does.
Simply change the extended data type in line 5 to the EDT you want to investigate, and the job makes a list of table fields that uses the EDT. You can also change the layer depending on what you are looking for.
For example, for InterCompanyCompanyId, searching through all the fields in the SYS layer:
While I love using the cross reference function in Dynamics AX 2012 (and am training myself to use it more often), the cross reference in our environments are often not up to date. Unfortunately this is especially true for our client development environments.
I wrote a job to find all the table fields that is based on a Base Enum. Simply change the enum name in line 5 to the enum you want to investigate, and the job makes a list of table fields that uses the enum. In my case I only needed tables in the ISV and up, but you can tweak it for all layers, or only one.
For example, for InterCompanyOrigin enum, searching through all the fields in the SYS layer:
//Tina van der Vyver
staticvoid enumCrossReference(Args _args)
EnumName enumName =enumStr(InterCompanyOrigin);
EnumId enumId = enumName2Id(enumName);
setPrefix(strFmt("Enum: %1", enumName));
whileselect parentId, utilLevel, Name, id from utilfield
where utilfield.recordType== UtilElementType::TableField
Today I add to compare the projects in an acceptance environment with the projects in the test environment. I did this so that I can make backups of the projects in test that are not in acceptance yet, before I import the acceptance model store.
Here in the simple job I wrote to show an list of shared projects in an infolog. You can change #ProjectSharedPath to see private projects or UtilEntryLevel::var enum so see projects in other layers.
Microsoft has an extremely useful .NET method named ExportAsFixedFormat() for exporting office files to PDF. For example, you can invoke the ExportAsFixedFormat() method on an Excel Workbook object and a PDF file is then created in the folder of your choice.
Unfortunately the documentation on how to use this in function in Dynamics AX is a little lacking. In the .NET documentation most of the parameters are described as optional, while in Dynamics AX you have to pass all the parameters.
The last parameter is a pointer to the FixedFormatExt class. It is not necessary to pass an actual value, but the method does not accept null. Saveen Reddy describes in this post how to pass an empty value in C#. In Dynamics AX is even more tricky, since you do not have access to System.Reflection.Missing.Value. You need to create an object like this:
System.Type type = System.Type::GetType("System.Reflection.Missing");
System.Reflection.FieldInfo info = type.GetField("Value");
It is also possible to create PDF’s form Word Documents. I’ll post an example if I write a job to do that in the future.
UPDATE 26 December 2014:
A senior colleague wanted to achieve something similar and I offered him this job. He pointed out that an instance of Excel is opened every time the job is run, but never closed. You can see this clearly in the Task Manager.
If you want to use this job, experiment with adding xlWB.Close and/or xlApp.Quit, and keep an eye op the running applications in the Task Manager.
Today I quickly wanted to see which fields in the PurchLine table are mandatory. Purchline is a large table, so instead of checking the properties of each field, I quickly wrote a job that displays an info log of all the mandatory fields. I used the DictClass example script from Microsoft, and adapted it so that it generates a list with all the fields in the table.
This job can be easily changed to display the fields of other tables, simply change the tableName variable. It can also be changed to display other properties like ‘Allows edit on create’. For this you need to change the #DBF_Mandatory flag to another flag defined in the macro:
This script uses a number of interesting things like macros, dictField and dictTable. I’ll write separate posts for these topics soon. Until then, here is a simple jobs that lists all the fields in a table and their properties: