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

Why is my changes ignored to releaseupdate scripts in dynamics ax 2012 r2
What is “old sys” exactly and why would I receive errors in 2012 because of a missing Macro?
How to filter records in line grid based on selected record in header grid?
Dynamic linking gets cleared when inserting new records
Box::info showing “refreshEx”
How to filter lookup values on a dialogfield in Report Dialog based on another dialogfield in AX 2012 AOT reports?
Adding scrollbar to a Group in AX 2012 form
Table query inconsistent
AX2012 Sales Order Creation through AX Classes
How can I loop over Tables which contain specific characters in their AOT name and delete the data?
Having button that runs code, but doesn't submit data to (or validates against) table
Where are Duties (table name) stored in AX?
Advanced query range
How to read from an Excel file?
group by clause in X++
Determine the number of affected rows by an update_recordset call in Dynamics 4.0?

Categories

HOME
httparty
search
kentico
porting
merge
jmx
interface
themes
sublimetext
tivoli
visual-studio-emulator
azure-container-service
title
flume
modal-dialog
discrete-mathematics
computer-science
fosrestbundle
jsonpath
supervisor
mongodb-csharp
coin3d
forgot-password
jquery-ias
r-mice
ios10.2
angular-routing
pimcore
object-storage
fat
custom-post-type
outliers
wcag
paperjs
quantlib
google-earth
constexpr
scatter3d
modalviewcontroller
fiware-cygnus
google-earth-engine
preloader
chronicle-map
tcc
avcapturedevice
file-sharing
wc
nanoc
xbmc
spring-integration-sftp
singleinstance
excel-dna
seq
lsyncd
flyout
cd-burning
mathcad
gets
chromium-os
omxplayer
iotivity
cda
findfirst
np-spring
cycle2
jparsec
character-replacement
custom-errors
sapi
gocql
iokit
r-package
microsoft-reporting
alloy-ui
omnifaces
google-refine
user-permissions
infosphere-spl
pseudo-class
machine-instruction
paw
kissfft
grails-domain-class
tinyxml
memset
sbcl
ora-06550
solace-mq
c++builder-xe5
isqlquery
mongohq
gpars
flex++
cascadingdropdown
argouml
onmousemove
adobe-media-server
objectquery
floating-point-exceptions
stress
node-redis
procedures
metaweblog
delimited-text
office-2007
addchild
skype4java
feasibility
google-wave

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App