I came across a requirement where I needed to convert users entry from Hirjri Calendar date (the Islamic Calendar) into the Gregorian Calendar. In previous posts, I have shown how to convert Gregorian Date (date data type in Dynamics AX) into Hirjri… if you are interested in those check them out here:
In order to convert a Hirji date into Gregorian, I used the .NET classes referenced in the any Dynamics AX standard version.
Enjoy!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | //Amer Atiyah, http://blog.amerax.net static date hijri2GrDate(DAPHijridateStr hijriDateStr) { System.Globalization.CultureInfo arCul = new System.Globalization.CultureInfo("ar-SA"); System.Globalization.CultureInfo enCul = new System.Globalization.CultureInfo("en-US"); System.DateTime tempDateTime; str strTemp; System.String[] arr; date grDate; ; //all expected dates formats arr = new System.String[18](); arr.SetValue("dd M yyyy", 0); arr.SetValue("yyyy/MM/dd", 1); arr.SetValue("yyyy/M/d", 2); arr.SetValue("d/M/yyyy", 3); arr.SetValue("dd/MM/yyyy", 4); arr.SetValue("yyyy-MM-dd", 5); arr.SetValue("d/MM/yyyy", 6); arr.SetValue("dd/M/yyyy", 7); arr.SetValue("yyyy-M-d", 8); arr.SetValue("dd-MM-yyyy", 9); arr.SetValue("yyyy MM dd", 10); arr.SetValue("d-M-yyyy", 11); arr.SetValue("d-MM-yyyy", 12); arr.SetValue("dd-M-yyyy", 13); arr.SetValue("d M yyyy", 14); arr.SetValue("dd MM yyyy", 15); arr.SetValue("yyyy M d", 16); arr.SetValue("d MM yyyy", 17); try { tempDateTime = System.DateTime::ParseExact(hijriDateStr, arr, arCul, System.Globalization.DateTimeStyles::AllowWhiteSpaces); } catch { error("Unexpected Hirji date format."); return datenull(); } strTemp = tempDateTime.ToString("dd/MM/yyyy"); grDate = str2date(strTemp, 123); return grDate; } |
It might a great idea if you added this method to the “Global” class, like what I did :).
If you wanted to write a an X++ code to generate a number sequence and assign it to a field, you might use the following X ++ statement.
1 | yourTableBuffer.Field = NumberSeq::newGetNum(NumberSequenceReference::find(TypeID2ExtendedTypeId(TypeId(YourExtendedDataType)))).num(); |
And for the continuous number sequence (notice the “true” parameter):
1 | yourTableBuffer.Field = NumberSeq::newGetNum(NumberSequenceReference::find(TypeID2ExtendedTypeId(TypeId(YourExtendedDataType))), true).num(); |
But, what you could do if you have that field in form and you want to generate a number sequence while the user creates a new record is the class NumberSeqFormHandler.
NumberSeqFormHandler is a great class that doesn’t only take care of generating a new number sequence for your field… but also it takes care of removing or inserting that number in the Number Sequence List table when the number is not used (in case that the record hasn’t been inserted although the number has been already generated).
To use the NumberSeqFormHandler class, you have to declare a NumberSeqFormHandler object in the class declaration. Also you have to create a method at the Form level like the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | //Form level method NumberSeqFormHandler numberSeqFormHandler() {; //you should have been declared numberSeqFormHandler variable in the ClassDeclaration of your form if (!numberSeqFormHandler) { numberSeqFormHandler = NumberSeqFormHandler::newForm(NumberSequenceReference::find(TypeID2ExtendedTypeId(TypeId(YourExtendedDataType))).NumberSequence, element, YourDataSourceName, fieldnum(YourTableName, Field)); } return numberSeqFormHandler; } |
Then you need to actually call the NumberSeqFormHandler class methods like:
1 2 3 4 5 6 7 8 9 | //Form methods public void close() { if (numberSeqFormHandler) { numberSeqFormHandler.formMethodClose(); } super(); } |
1 2 3 4 5 6 | //DataSource method public void write() { element.numberSeqFormHandler().formMethodDataSourceWrite(); super(); } |
1 2 3 4 5 6 7 8 9 10 | //DataSource method public boolean validateWrite() { boolean ret; ret = super(); ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret; return ret; } |
1 2 3 4 5 6 | //DataSource method public void linkActive() { element.numberSeqFormHandler().formMethodDataSourceLinkActive(); super(); } |
1 2 3 4 5 6 | //DataSource method public void delete() { element.numberSeqFormHandler().formMethodDataSourceDelete(); super(); } |
1 2 3 4 5 6 7 8 9 | //DataSource method public void create(boolean _append = false) { element.numberSeqFormHandler().formMethodDataSourceCreatePre(); super(_append); element.numberSeqFormHandler().formMethodDataSourceCreate(); } |
By this you will have your form works efficiently with the Number Sequence engine of Dynamics AX and you don’t have to write any code at the table level… so remove all that code that you might have written at the initValue method of your table.
One last important thing, NumberSeqFormHandler works with Continuous and non-Continuous number sequences. But if you want to “regenerate” the unused numbers that have been previously generated, you have to set your number sequence as Continuous of course.
In a previous post, I descriped in deatils how to gte (and set) Hijri date in Microsoft Dynamics AX 2009. In that post I have shown how to get Hirji date in Dynamics AX by calling a SQL function from X++.
A calleague of mine has also came up with another great idea to handle the Hirji date using the CLR Interoperability. The standard Dynamics AX 2009 comes with a set of very important .NET libraries referenced to be used automatically in Dynamics AX 2009.
What you could use out of those libraries: System.Globalization library of .NET framework. But of course, you have to use a string to show the value of that date since you cannot get a Hirji date (with its values like 1430 as a year) and assign it to an X++ date datatype.
Check out this code to have the Hirji date converted from X++ gregorian date:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | display STRExtendedDT ExpieryDate_H() { System.Globalization.Calendar Calendar = new System.Globalization.HijriCalendar(); System.Globalization.DateTimeFormatInfo hirjiDate; System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ar-SA",false); System.DateTime dt; STRExtendedDT dateString; ; dt = this.ExpieryDate; hirjiDate = cultureinfo.get_DateTimeFormat(); hirjiDate.set_Calendar(Calendar); dateString = dt.ToString("dd/MM/yyyy", hirjiDate); return dateString; } |
You will get :
If you ever tried to modify the LedgerJournalTransDaily form (the Ledger Jourlan Lines form) you would notice a forest of X++ codes executed on every click, initializations, closing, fields modifications… etc. Of course this makes sense because this form is basically the backbone of financial transaction of this Dynamics AX, which in turn the backbone of all modules of Dynamics AX.
One of the common classes executed in this form is LedgerJournalFormTrans class. Basically this class controls the controls of any form where LedgerJournalTrans table is a datasource for that form. It simply controls the visibility, edibility and validity of most of the controls on that form based on the “status” of the current Ledger Journal Trans and Ledger Journal Table. Whenever a user fills data, reads data, and clicks buttons and menu buttons.. a call for a method in that class is executed to control the new write/read/event.
Actually LedgerJournalFormTrans is an important class of a series of extended classes. Those classes are like the following:
-
JournalForm --> JournalFormTrans --> LedgerJournalFormTrans --> LedgerJournalFormTrans_Payment
-
JournalForm --> JournalFormTable --> LedgerJournalFormTable
I believe from the name you could tell what all of those classes are all about.
I have read a very interesting article talking about the new editor of X++ that will be shipped as part of the new version of Dynamics AX, 6.0.
The new editor looks more “fashionable” than the current one. You could specify font styles, colors, sizes… etc. Also types of words that you write in the editor are now more colorful. Integers, operators, and others are now recognized in different colors.
Mainly, these are the features of the new Dynamics AX editor:
-
Support for multiple fonts and styles (comments are in a different font in italic)
-
Differentiated coloring of strings and numbers
-
Operators coloring
-
Change tacking margin
Here are some pics for it
Search the site
Dynamics AX 2012 Event
Recent Posts
- D365FO | Cannot Connect to SQL Server Database on Your Cloud Test Machines
- Intro to Microsoft Dynamics AX in Arabic – سلسلة حلقات مايكروسوفت داينامكس إيه إكس بالعربية
- Microsoft Dynamics Launch – Sunday, 24th February – Intercontinental Hotel, Riyadh
- Files of Our AX Brains Dec 2012 Event
- It was a great day!
- Tomorrow is the day for our Dynamics AX Brains Technical Seminar
- Dynamics AX Brains December 2012 Technical Seminar
- Windows Server 2012: Built from the Cloud Up
Tags
Archives
- October 2019 (1)
- January 2014 (1)
- February 2013 (1)
- December 2012 (4)
- September 2012 (2)
- December 2011 (2)
- November 2011 (3)
- July 2011 (3)
- June 2011 (4)
- May 2011 (3)
- April 2011 (4)
- March 2011 (12)
- February 2011 (2)
- January 2011 (3)
- December 2010 (1)
- November 2010 (1)
- October 2010 (5)
- August 2010 (1)
- July 2010 (3)
- June 2010 (4)
- May 2010 (5)
- April 2010 (1)
- March 2010 (9)
- February 2010 (4)
- January 2010 (4)
- December 2009 (11)
- September 2009 (1)
- August 2009 (1)
- July 2009 (2)
- September 2008 (1)
Random Testimonial
- ~ Ehab Elmetwally, ERP Business Unit Manager at Alfanar IT
"I worked with and managed amer for nearly 1 year and a half. A real technical consultant with tangable expierience. His capabilities and attitude enabled him to be of a big benefit to our departement. I recommend him as a professional technical consultant"
- Read more testimonials »