Read Weater forecast detail in Ax


Description:-

In this article we will see about how to get weather forecast details in dynamics ax. Here i have created sample demo example to read weather forecast data from yahoo and display in ax. Here i have created Job to get data from server and display in ax. When we get data from server then the data will be on Xml format to read data from xml we have to create XElement and read data from xml file and display on ax.

To read data and get data from server i have created demo example to understand easily. Create job and Copy below code to get data from Yahoo server and display it on the Information log in ax.

Code:-

Static void weatherForecast(Args _args)
{
  XmlDocument         doc = new XmlDocument();
  XmlNamespaceManager ns;
  XmlNodeList         nodes,nodes1;
  XmlNode                node,node1;
  //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 : returnconnull();
    }
  }
  ;
  //addresszipCode = _args.record();
  doc.Load("http://xml.weather.yahoo.com/forecastrss?p=INXX0001&u=c" );// +addresszipCode.ZipCode +’&u=c’);
  // Setup namespace manager for XPath
  ns = new XmlNamespaceManager(doc.nameTable());
  ns.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");
  nodes1 = doc.SelectNodes("//rss/channel/item/yweather:condition", ns);
  node1= nodes1.nextNode();
  setprefix("Weather forecast");
  //info(strFmt("%1,Temp : %2,%3", node1.attributes().getNamedItem("date").InnerText(), node1.attributes().getNamedItem("temp").InnerText(), node1.attributes().getNamedItem("text").InnerText()));
  // Getforecast 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(node.attributes().getNamedItem("date").InnerText());
    info(strFmt("%1-(%2)", conpeek(day(node.attributes().getNamedItem("day").InnerText()),2), node.attributes().getNamedItem("date").InnerText()));
    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();
  }
}

Related Posts

Previous
Next Post »

1 comments:

comments

Thanks for comments.....