Skip to main content

Weather forecasting using X++

In todays competitive business world, there are many factors which determine the profit or loss.

Climatic conditions has its own impact and is becoming increasingly important for the corporates.
Like Demand forecast, weather forecast can be very helpful in business planning.
This Job is an attempt to predict the weather conditions in advance and organize things in such a way which will help the companies not
only to optimize their resources but also maximize their profits.
In the example, I used Yahoo released rss weather feeds: http://weather.yahoo.com/rss and XML programming to get the climatic conditionsThe format of the URL for the feed is:
http://xml.weather.yahoo.com/forecastrss?p=USNY0996&u=f
p is a US zip or a Yahoo! Weather location ID
u is the temp. units. ‘F’ for Fahrenheit (default) and ‘C’ for celciusstatic void weatherForecast(Args _args)
{
XmlDocument doc = new
XmlDocument();

XmlNamespaceManager ns;
XmlNodeList nodes;
XmlNode node;
//AddressZipCode addresszipCode;
container day(str _day)
{
;
switch(_day)
{
case ‘Mon’ : return [1,'Monday'];
case ‘Tue’ : return [2,'Tuesday'];
case ‘Wed’ : return [3,'Wednesday'];
case ‘Thu’ : return [4,'Thursday'];
case ‘Fri’ : return [5,'Friday'];
case ‘Sat’ : return [6,'Saturday'];
case ‘Sun’ : return [7,'Sunday'];
Default : return connull();
}
}
;
//addresszipCode = _args.record();
doc.Load("http://xml.weather.yahoo.com/forecastrss?p=
UKXX0085&u=c"
);// +
addresszipCode.ZipCode +’&u=c’);

// Set
up namespace manager for XPath

ns =
new XmlNamespaceManager(doc.nameTable());

ns.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");
// Get
forecast with XPath

nodes
= doc.SelectNodes("//rss/channel/item/yweather:forecast", ns);

node =
nodes.nextNode();

setprefix("Weather forecast");
while
(node)

{
info("—————————————————–");
info(conpeek(day(node.attributes().getNamedItem("day").InnerText()),2));
info("—————————————————–");
info( node.attributes().getNamedItem("text").InnerText());
info(‘Min :’ +
node.attributes().getNamedItem("low").InnerText());

info(‘Max :’ +
node.attributes().getNamedItem("high").InnerText());

if(dayofwk(today()) ==
conpeek(day(node.attributes().getNamedItem("day").InnerText()),1))

{
info(‘Current :’ +
node.attributes().getNamedItem("code").InnerText());

}
else
{
info(‘Current : NA’);
}
node = nodes.nextNode();
}
}
Note: 1) An essential pre-requisite for the code to work is the URL should not be blocked by the firewall.2)We can directly use this job as an menuitemaction button by adding the job in menuitems under actions, Then add the button in the AddressZipcode form , for that make use of the commented code of AddressZipcode in the above Job.Here are some example location IDs (do not include the city name) or use the existing Zipcodes of AX
  • Beijing: CHXX0008
  • Helsinki: FIXX0002
  • London: UKXX0085
  • Moscow: RSXX0063
  • Munich: GMXX0087
  • Paris: FRXX0076
  • Riyadh: SAXX0017
  • Tokyo: JAXX0085







For more details on the Yahoo! Weather RSS feed and other location IDs, please visit http://developer.yahoo.com/weather/index.html." Don’t bother about weather"

Popular posts from this blog

Mark All for Open Cust Trans and Open Vend Trans

We have situations where there are lots of open transactions that need to be settled against each other. This can be the case if auto settlement is turned off. One solution is to add a "Mark All" button to the custOpenTrans or vendOpenTrans forms. This button "checks" the mark checkbox on every line. The user can then uncheck several lines if needed and Update to settle the lines. The code below is an example of what we used on the open vendor transaction screen. The code is very similar on the AR side. One note: I used vendTable.AccountNum in the code below. That should be generalized to work with any buffer that is passed into the open trans form. void customMarkAll() { VendTransOpen localVendTransOpen; VendTrans localVendTrans; container conSum; int linesProcessed; ; //show wait cursor startLengthyOperation(); element.lock(); //remove all prior markings specOffsetVoucher.deleteSpe...

Print Report in Microsoft Dynamics AX 2009 through X++

I am trying to print sales confirmation report on a button click which I have added on Sales Order Detail form in Microsoft Dynamics AX 2009. On click event of that button, I have written following code: void clicked() {     Args                args;     ReportRun           reportRun;     SalesFormLetter     salesFormLetter;     PrintJobSettings    printJobSettings;     CustConfirmJour     custConfirmJour;     RecordSortedList    list                = new RecordSortedList(55);     SalesTable          salesTableUpdate;     ;     SELEC...

Creating Free Text Invoice through X++ code

Job: Calling class from job to run the class public void freeTextInvoicePostTestJob() { Dialog dialog; DialogField dlgCustAcc; DialogGroup dialogPeriodLengthGroup, dialogPeriodLengthGroup1; DialogField dlgLedgerAcc; ; dialog = new Dialog("Free-Text Invoice"); dialogPeriodLengthGroup1 = dialog.addGroup('Cust Table'); dlgCustAcc = dialog.addField(typeid(CustAccount)); dialogPeriodLengthGroup = dialog.addGroup('Ledger Table'); dlgLedgerAcc = dialog.addField(typeid(LedgerAccount)); if(dialog.run()) { if(dlgCustAcc.value() && dlgLedgerAcc.value() != '') FreeTxtInvoiceCreatePost::main(dlgCustAcc.value(), dlgLedgerAcc.value()); else throw error(strfmt("Either CustAccount or LedgerAccount info is missing.")); } } Class: Which creates the free text invoice class FreeTxtInvoiceCreatePost { } static void main(CustAccount _custAccount, LedgerAccount _ledgerAccount) { CustInvoiceTable custInvoiceTable; ...