Sunday, June 26, 2011

Call webservice using SQL Server

Query:
How can I call an AIF service using SQL Server 2008?

Answer:
You can use http://technet.microsoft.com/en-us/sqlserver/ff686773.aspx to see how it is done.

Wednesday, June 22, 2011

Dynamics AX Run Time Dialog

Query:
Can I create a dialog on run time?

Answer:
Use the following class
///

///  This is a class to create dynamic dialog on the fly
///

///
/// Usage
/*
static void testDynamicDialog(Args _args)
{
  CustomDialog   diag;
  List           types = new List(Types::Integer); // typeId is an integer
  List           fields;
  ListEnumerator enum;
  DialogField    field;
  ;

  // the dialog shall contain fields for the following types
  types.addEnd(typeId(EmplId));
  types.addEnd(typeId(Itemid));
  types.addEnd(typeId(ProdId));
  types.addEnd(typeId(CustAccount));

  // crate and show
  diag = new CustomDialog(types,"Dynamic Dialog");
  diag.run();

  // show values in the Infolog
  fields = diag.parmFieldList();
  enum   = fields.getEnumerator();

  while(enum.moveNext())
  {
    field = enum.current();
    info(field.value());
  }
} */
///


class MSTACustomDialog extends Dialog
{
    List fieldList;
}


public List parmFieldList()
{
    return fieldList;
}

void new(List typeList, Caption _caption = '', Object _caller = null, str _parmstr = '', Form _form = new Form(formStr(Dialog)))
{
    ListEnumerator enum;
    ;

    if(typeList == null)
      error("@BCS3969");

    super(_caption, _caller, _parmStr, _form);

    fieldList = new List(Types::Class);
    enum      = typeList.getEnumerator();

    while(enum.moveNext())
    {
      fieldList.addEnd(this.addField(enum.current()));
    }
}

Monday, June 13, 2011

Reading CSV File in AX

Query:
How can I read a csv file in AX?

Answer:
use the following code,

public void run()
{
    #File
    CommaTextIo commaTextIo;
    FileIOPermission permission;
    container containFromRead;
    int x;
    int cols;
    PurchIdBase purchId;
    LineNum lineNum;
    ;
    super();
    if(!this.validate())
    {
        return;
    }


    try
    {
       
        permission = new FileIOPermission(filePath, #io_read);
        permission.assert();


        commaTextIo = new CommaTextIO(filePath, #io_read);
        containFromRead = commaTextIo.read();


        while(containFromRead)
        {
            cols = conLen(containFromRead);
            for(x=1; x <= cols; x++)
            {
                info(any2str(conpeek(containFromRead, x)));
            }
            containFromRead = commaTextIo.read();
        }
        commaTextIo = null;
    }
    catch(Exception::Error)
    {


    }
}

CommaTextIO not initialized error

Query:

I am getting commatextio not initialized error and it is not going away. I am sure my code is right.

Answer:

Make sure you are on the correct tier (client or server) and make sure you have permission on that file for the specific tier.

Hint: see the main and construct methods make sure they don't have only server keyword.

Wednesday, June 8, 2011

Passing arguments between two forms

Query:
How can I pass information from 1 form to another?

Answer:
IN the clicked button of form A write following code,
void clicked()
{
    Args args;
    FormRun formRun;
    ;
    super();

    args = new Args(formstr(FormName));
    args.parm(parameters);
    formRun = classFactory.FormRunClass(args);
    formRun.init();
    formRun.run();
    formRun.wait();
    formRun.detach();
    parenttable_ds.refresh(); // Refreshing parent table DataSourceTable
    parenttable_ds.executeQuery(); // Refreshing Parent DataSourceTable Query
}

IN form B init method write following code
args = element.args();
args.parm()

Sunday, June 5, 2011

Converting Real Number to TIme

public static str 5 num2Time(real _hours)
{

    int realPart;
    int decimalPart;
    real hours;
    str hoursStr;
    str minStr;
    int decimalLocation;
    str finalMinutes;
    ;
    try
    {
        hours = _hours;
        hoursStr = num2str(hours, 0, 2, 1, 0);
        decimalLocation = strfind(hoursStr, ".", 0, strlen(hoursStr));
        hoursStr = substr(hoursStr, 0, decimalLocation);
        hoursStr = trimString(hoursStr, ["."]);
        minStr = num2str(hours, 0, 2, 1, 0);
        minStr = substr(minStr, decimalLocation, strlen(minStr) - strlen(hoursStr));
        minStr = trimString(minStr, ["."]);
        realPart = str2int(hoursStr);
        decimalPart = str2int(minStr);
        finalMinutes = hoursStr + ":" + (int2str(60 * decimalPart / 100) == "0" ? "00" : int2str(60 * decimalPart / 100));
        return finalMinutes;
    }
    catch
    {
        return num2str(_hours, 0, 2, 1, 0);
    }
}

Wednesday, June 1, 2011

CLR Exception Catch

Query: How to catch CLR Exception?
Answer:  
catch (Exception::CLRError)
{
        info("Caught 'Exception::CLRError'.");
        netExcepn = CLRInterop::getLastException();
        info(netExcepn.ToString());
}

Tuesday, May 31, 2011

How to open an exe from Dynamics AX

 WinAPI::shellExecute(path);

SSRS A4 Print Layout

If you use Reporting Services, I bet you have spent a while trying to get the reports to print out as expected! I'm not sure why something that wastes so much of everybodies time (printing things out properly) is not well-known and fixed in software now - it should be impossible to get it wrong. The print knows its paper size, the software knows the paper size yet it prints out most of your document on one sheet and then a little strip on the next - obviously what you wanted!
Anyway, in reporting services there are some quirks that you need to know about in order to get your report correct.
1) Select Report - Report Properties and the Layout tab. There are paper sizes and margins in here. Note that the page sizes here need to match the physical paper size. I'm not sure what effect they have because it doesn't draws these on your report design!
2) You might think that is it BUT you then need to right-click on the grid area of the report in the layout view and choose properties (properties of the body of the report) and lo and behold there is another field here called "Size" which consists of width,height in measurement units (mm, inches etc) which defines the area of the report body. For some reason this is not restricted by the page size in report properties and you won't know if you make this too big! Anyway, this needs to equal the page size minus margins if you want it to fit on one sheet.

Example A4 paper is 210mm by 297mm so you set the report layout (in Report -> Report Properties) to these figures and then suppose you set the margins to 10mm all the way round. The report body should be set to 210 - 20 (for width) and 297 - 20 (for height) when in portrait or 297 - 20 (width) x 210 - 20 (height) when in landscape mode. It sounds really simple but it still takes time to find these things out!

More Links: http://blogs.msdn.com/b/bwelcker/archive/2005/08/19/454043.aspx