x++


WeekOfYear in X++ using .net lib


static void Job5(Args _args)
{
int i;
System.DateTime netDttm;
System.Int32 intnet;
;
netDttm = new System.DateTime(2011,03,20 ,13,44,55);
intnet = System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(netDttm, Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday);
i = intnet;
info(int2str(i));
}
I tried the in vb.net it works fine but doing the same in x++(using .net lib) it shows syntax error..All I am trying is to get the week no. from a supplied date. Any insight would be appreciated.
P.S. I found another solution to this which is I created a dll file in VS .net and added this to Reference node(AOT)of AX. It has shorten the code in AX
static void Job5(Args _args)
{
weekofyear.wof asd;
;
asd = new weekofyear.Wof();
print asd.weekofyr(today());
pause;
}
try this
int i;
System.DateTime netDttm;
System.Int32 intnet;
System.Globalization.CultureInfo cultureInfo;
System.Globalization.Calendar calendar;
System.Globalization.CalendarWeekRule calWeekRule
;
netDttm = new System.DateTime(2011,03,20 ,13,44,55);
cultureInfo = System.Globalization.CultureInfo::get_CurrentCulture();
calendar = cultureInfo.get_Calendar();
intnet = calendar.GetWeekOfYear(netDttm, System.Globalization.CalendarWeekRule::FirstFourDayWeek, System.DayOfWeek::Sunday);
i = intnet;
info(int2str(i));
[Note to any future readers: The following described an error in the original code Indranil posted; it does not apply to the code currently in the question, because Indranil fixed this error. The other error was dealt with in another answer from someone else :-).]
You shouldn't be passing a string as the first argument to GetWeekOfYear; it wants a System.DateTime (http://msdn.microsoft.com/en-us/library/system.globalization.calendar.getweekofyear.aspx). (At least, that's true in ordinary .NET; I don't know whether Dynamics AX does some other magical thing. I doubt it does.)
(But if and when you do want a date in the form of a string, those backslashes \ should be forward slashes /.)
Just make sure you load the correct CultureInfo if you expect this code to support word wide locations. Loading the current CultureInfo will load the servers preferred culture. If the user is en-gb and the server is en-us, you first day of week will be incorrect.
To load a specific cultureinfo you can simply do this:
System.Globalization.CultureInfo arCul = new System.Globalization.CultureInfo("en-US");
In the example chosen as answer, the code loads cultureinfo, but the cultureinfo is not used as parameter to the GetWeekOfYear method, which doesnt really make any sense. Instead you could send in the settings from the cultureinfo.

Related Links

Sorting by custInvoiceJour.Dimension
Refresh the main screen in ax dynamics 2009
How to insert into a table field with value from a display method dependent of string
x++ cannot read registry entry
How do I get the caller Form's name in the Insert() of a table in AX 2012?
How to lookup into another table using EDT AX 2012
Set a Date Value to a Date Field in AX2012
Determine if a job is running in X++ code
Dynamics AX 2012 parsing Int32 to table field integer
Cancel Sales order packing slip through x++
Transferring open account records between customers
How to make sure that a form is only opened once?
Extend system menu in Dynamics AX 2012?
How to show selected items of certain table on the different table in Dynamics AX 2012?
AllowEdit doesn't work properly in Dynamics AX
AX 2012 how to set args record datasource in X++

Categories

HOME
kentico
google-cloud-platform
turing-machines
gpu
themes
mstest
3d-reconstruction
google-admin-sdk
frontend
rcloud
fabric.io
opengl-es-3.0
angular-dart
naivebayes
spring-social
tput
endpoint
intercom
magnetic-cards
libusb
package-managers
event-sourcing
entitymanager
asp.net-mvc-viewmodel
wolframalpha
google-picker
solrcloud
sar
microsoft-ocr
event-store
resourcebundle
froala
onload
outliers
soot
livelink
card.io
dsx-desktop
mongoose-schema
subclipse
ssrs-2014
wc
apache-directory
strftime
plan-9
openresty
user-defined-fields
twilio-click-to-call
scalding
cd-burning
filenet
stax
hadoop-2.7.2
fiware-monitoring
wiredep
extjs-grid
cgi-bin
sony-lifelog-api
typemock
dnssec
matlab-deployment
bufferedinputstream
at-job
rmysql
alternate
tinyxml
drupal-nodes
sphinxql
model-driven-development
flex++
dolby-audio-api
jquery-1.9
server-administration
fb.ui
patricia-trie
subgraph
objectquery
pinch
expression-blend-4
promotion-code
drawtobitmap
django-paypal
ruby-1.8
timertask
build-environment
dsl-tools
lobo-cobra
visualj#
windows-identity
todos
business-model
leader
idatareader

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App