Skip to main content

Posts

Calculating easter sunday in different ways

Once a long time ago I found an interesting document on the inter web, describing different calendar systems. From that I made a php-class for my website that can calculate easter sunday in the gregorian calendar. Then it is easy to calculate the rest of the danish holidays as they are offset according to easter sunday (except of course those that have a fixed date). I translated that class in to x++. You can find it here: https://onedrive.live.com/redir?resid=9B63D38F981FFD1B!39710&authkey=!ABv0yYPULV3ReIE&ithint=file%2cxpo Today I got talking with a colleague about calculating easter sunday so he mentioned that he had also made a version of the calculation: http://stackoverflow.com/questions/11048524/how-to-calculate-easter-sunday-in-x So of course - being a bit nerdy - we just *had* to check if the routines arrived at the same result. So we came up with: static void EasterTest(Args _args) {     Yr x;     date easter(Yr yr) // Påskedag / påske sønd

Forcing the Name field of a salesline to be synchronized to the purchline when using Drop shipment

Using non-stock items in the daily business can be handled in Dynamics AX 2012 by using Direct delivery. You can use the Button "Direct delivery" from a sales order you have created, to create a matching purchase order. However if you use the Name field on the salesline to describe the specifications of the item you want to the vendor, the standard functionality does create the matching purchase order lines so that the name of the originating sales line is also used on the sales lines. Direct deliveries are handled so that the inventory transactions of the salesline are marked against the purchline, so I wrote this small script to be able to get the hang of how to find the direct delivery purchaselines from the saleslines records of a sales order. static void Job235(Args _args) {     SalesLine   salesLine;     PurchLine   purchLine;     InventTransOriginSalesLine itosl;     InventTransOriginPurchLine itopl;     InventTrans it,it1;     InventTable iTbl;     InventHandl

Returning a weeknumber from the standard calendar lookup form

A customer had a requirement for setting a week number for approximate delivery of purchased goods on shipment as an indication for the sales department of when the goods will be arriving. An integer field had been introduced on the table in question, and the customer wanted to be able to do a lookup in the standard calendar, but wanted a week number to be returned in stead of a date. I solved it like this: 1. For the field that was to contain ETAWeek there was an Extended Data Type called ETAWeek. On the EDT I put SysDateLookup in the FormHelp property 2. In the Form SysDateLookup I added a boolean variable in Classdeclaration. boolean calledFromIntegerField; 3. In the Form SysDateLookup - method init I added check to see if the SysDateLookup form was called from an integer form control. if (formRun.selectedControl() is FormIntControl)      calledFromIntegerField = true; 4.In the Form SysDateLookup - method closeSelect I added an extra else if block in the bottom to handle

Dynamics AX 2012 R2 - Export to Excel command button

Today I had some trouble getting a normally simple thing to work in an AX form. The form consists of to synchronized grids, and the user wanted an "Export to Excel" command button, so the active grid can be exported to Excel. Normally this is very simple as you just need to add a command button to the form in the ActionPane somewhere and you're home free. Not this time. It didn't work. I googled and found this: http://blogs.msdn.com/b/emeadaxsupport/archive/2009/09/07/how-does-the-export-to-excel-feature-work-under-the-hood.aspx and put a breakpoint in the performPushAndFormatting  method. I didn't reach my breakpoint and Excel didn't even start. Then I started to investigate the form. Maybe the tables of the datasources of the form had some obscure property that needed tweaking, but no. After pondering this for a while I found that the designer of the form had dropped a field group containing all the fields in the grid. Could that be the pro

Dynamics ax 2012 traversing selected records in a form data source

A classical developer challenge in Dynamics AX is to enable a form button when multiple records have been selected in the form by the user. This usually involves writing some form of loop (for or while or do-while) that starts out with calling _ds.getFirst() and continuing the loop as long as _ds.getNext() returns a tablebuffer. Well things got a little bit easier in AX 2012. In AX 2012 you can use the MultiSelectionHelper class. One example is the following that I encountered in AX 2012: Can you make the customer collection letter print out run for each selected collection record in the Print/Post collection letters form (Accounts receiveable / Periodic / Collections / Print/Post Collection letters). If we ignore the possibility for setting up print destination for running each report we can do this in two steps: 1) Change the "Multiselect" property of the "MenuButton" and the "Menuitembutton" in the MenuButton in the form from "Auto&quo

Dynamics AX 2012 ValidTimeState tables and form changing view from current to all

Valid Time State tables are new i AX 2012 a gives the developer the possibility to easily create tables that hold e.g. current setup data for various purposes, and at the same time keeping a "history" of the changes of the data in the table. For more reading: http://msdn.microsoft.com/en-us/library/gg861781.aspx I was tasked with doing a setup table with rates for calculating Vendor Bonus and I chose to base this a valid time state table. The customer asked for a button on the form, where you maintain the vendor bonus calculation setup data, so you could toggle viewing "Current setup" or "All setup" records (changing the view from actual to all records and vice versa in the form). I found that you can not change the ValidTimeStateAutoQuery property on the form data source in a form at run-time. It simply does not change anything, so I came up with the following solution: A boolean class member in the classdeclation method of the form: boolean

Show elements in a model from the ABOUT Dynamics AX form

Being in a situation where I needed to determine if a certain AOT-element was included in an installed model, I wonder why Microsoft didn't link the form showing installed models (Help / About Microsoft Dynamics AX / (link) Show installed models) or (Tools / Model management / Models installed) with the form showing Elements in installed models (Tools / Model management / Model elements. Opening the About Dynamics AX form you are able to access the list of installed models in the application, but you can not drill down to the elements included in the model. You'll have to go to the other form and make a filter to view the elements in a model. So I quickly made the attached code project, which simply adds a button (Elements) to the Installed models form, so that you can see a list of the elements included in the model. In the element list you can open the cross reference for each element, to make further drill down as to which elements are using the element included in the