Thursday, 19 June 2014

Read data from live website in Ax2012

With the help of following code we can easily read data from live website

static void ReaddataFromLivewebSite(Args _args)
{
    #DEFINE.BLOGCONTENT('http://www.lme.com/en-gb/metals/non-ferrous/copper/')
    int         curPos=1;
    int         endPos;
    int         startPos=1;
    str         data;
    str         internetURL;
    int         price;
    TextBuffer  textBuffer;
    System.Net.WebRequest request;
    System.Net.WebResponse response;
    System.IO.StreamReader  streamReader;

    request=System.Net.WebRequest::Create(#BLOGCONTENT);
    response= request.GetResponse();
    streamReader=new System.IO.StreamReader(response.GetResponseStream());
    textBuffer =new TextBuffer();
    textBuffer.setText('');
    data = streamReader.ReadToEnd();
    streamReader.Close();
    textBuffer.setText(data);
    textBuffer.regularExpressions(false);
    textBuffer.find('Cash Seller & Settlement', curPos);
    startPos=textBuffer.matchPos();
    textBuffer.find('3-months Buyer');
    endPos=textBuffer.matchPos();
    data=textBuffer.subStr(startPos, endPos - startPos);
    data =   strReplace(data,'',"");
    data =   strReplace(data,'',"");   
    data =   strReplace(data,' ',"");
    data =   strReplace(data,'',""); 
    internetURL= strRem(strreplace(data,'Cash Seller & Settlement',''),'"');
    price = str2int(internetURL);
    internetURL = int2str(price);
    info(internetURL);
    response.Close();

}

Tuesday, 10 June 2014

Calculate LabelIds against Label field Id in AX2012 using X++

I have calculated a total number of label id's against Label file id . In my case Label file Id is "NVS".

static void maxLabelIds(Args _args)
{
    SysLabel   SysLabel;
    int maxLabelId;
    ;
    SysLabel =  new SysLabel('EN-US');
    maxLabelId = SysLabel.maxLabelId('NVS');
    print maxLabelId;
    pause;
}