Tuesday, January 11, 2011

Adding a field on dialog by addfield() method, when the type of EDT is known at run time, in Dynamics AX 2009

Possible situations when:

1.       EDT type is fixed and is known at design time.

public Object dialog()
{
            DialogRunbase       dialog = super();
;
            dlgTransDate                   = dialog.addField(typeid(CustAccount));

            return dialog;

}
       
         
2.     EDT Name is known in some situation.

public Object dialog()
{
    DialogRunbase dialog;
    Str                  edtName = “CustAccount”;
    ;
    dialog      = super();
    dialog.addField(new sysDictType(new Dictionary().typeName2Id(edtName)).extendedTypeId());
    return dialog;
}

3.     EDT Name is not known at design time, but is known at Run time from a table field.
public Object dialog()
{
    DialogRunbase           dialog;
    str                            edtName;
    dictField                    dictField;
    ;
    dialog            = super();
    dictField         = new DictField(tablenum(CustTable),fieldnum(CustTable, AccountNum));
    edtName       = extendedTypeId2name(dictField.typeId());
    //Get the EDT information from field of a table. Here Field AccountNum from table CustTable
    //has been taken for example.
    dialog.addField(new sysDictType(new dictionary().typeName2Id(edtName)).extendedTypeId());
    return dialog;
}


Monday, January 3, 2011

Create dialog without DialogRunbase class in Dynamics AX 2009

static void xppdialogWithOutRunBase(Args _args)
{
    Dialog          dialog;
    DialogField     df;
    CustAccount     custAccount;
    ;
    dialog      = new Dialog('My Dialog');
    df          = dialog.addField(TypeId(CustAccount));
    if (dialog.run())
    {
        custAccount = df.value();
        if (CustTable::exist(custAccount))
        {
            info(strfmt("Customer account: %1", custAccount));
        }
        else
        {
            throw error("Customer not found");
        }
    }
    else
    {
        throw error("sorry this function needs a customer");
    }
}

Get list of all open windows using X++ Code

static void xppGetAllWindowsOpen(Args _args)
{       
        hWnd Parent;
        hWnd handle;

        hWnd mdi;
        #WinApi

        dialog d = new Dialog();
        DialogTabPage dt;

        str text;
        ;

        d.caption("All the windows");
        d.windowType(FormWindowType::PopUp);

        Parent = infolog.hWnd();
        mdi = WinApi::getWindow(Parent, #GW_CHILD);

        handle = WinApi::getWindow(mdi, #GW_CHILD);
        text = WinApi::getWindowText(handle);

        if(text)        
       {               
                dt = d.addTabPage(text);
                d.addText(text);
        }
        if(handle)       
       {               
                  while(handle)               
                  {                       
                        handle = WinApi::getWindow(handle, #GW_HWNDNEXT);
                        text = WinApi::getWindowText(handle);

                        if(text)                       
                       {                               
                                dt = d.addTabPage(text);
                                d.addText(text);
                        }               
               }
        }
        d.run();
}

Get Column Name from Column Number of Microsoft Excel in Dynamics AX 2009 by X++ Code

Get Column Name from Column Number of  Microsoft Excel in Dynamics AX 2009 by X++ Code

str xppColumnNum2ColumnName(counter   _excelColumn)
{
    str     returnRange;
    int     temp;
    int     modvalue;
    int     divValue = _excelColumn;

    str 1 returnColumnName(counter  _alphaPos)
    {
        temp = 64 + _alphaPos;

        return num2char(temp);
    }
    ;
    while(true)
    {
        if(divValue > 26)
        {
            modvalue        = divValue mod 26;//will always be equal or  less than  26
            divValue        = divValue div 26;//can be greater than 26

            returnRange     += returnColumnName(modvalue);
        }
        else
        {
            returnRange += returnColumnName(divvalue);
            break;
        }
    }

    return strReverse(returnRange);
}

Marking a Sales Line with Purch Line in Dynamics AX 2009, With X++ Code,

Partial/Complete marking of Sales Line with X++ Code:

static void xppInventMarking(Args _args)
{
    InventTrans                          purchLineTrans;
    InventTrans                          salesLineTrans;
    SalesLine                              salesLine;
    TmpInventTransMark            tmpInventTransMark;
    Map                                      mapMarkNow;
    InventDim                             inventDim;
    MapEnumerator                     mapEnumerator;
    Qty                                       qtyMax;
    container                              con;
    Qty                                       qty;
    TmpInventTransMark             tmpInventTransMarkNow;

   ;

 //Say,Sales Line has sales qty = 10
//Say, Purch Line has PurchQty = 10 and we want to mark only 1, partial
    ttsbegin;
    salesLineTrans            = InventTrans::findTransId('00000451_068', true);
    purchLineTrans           = InventTrans::findTransId('00000452_068', false);

    inventDim                  = purchLineTrans.inventDim();
    salesLine                     = salesLineTrans.salesLine();


    // setup marking
    [con, qty]          = TmpInventTransMark::packTmpMark(salesLine.ItemId, inventDim, salesLine.InventTransId, -10);
    salesLine.SalesQty  = -1;
    mapMarkNow          = Map::create(con);
    mapEnumerator       = mapMarkNow.getEnumerator();

   while (mapEnumerator.moveNext())
      {
         tmpInventTransMark = mapEnumerator.currentValue();
         if (tmpInventTransMark.InventTransId == purchLineTrans.InventTransId)
           {
              break;
           }
      }

   buf2buf(tmpInventTransMark, tmpInventTransMarkNow);
   tmpInventTransMarkNow.qtyMarkNow = salesLine.SalesQty;

   tmpInventTransMarkNow.insert();

   mapMarkNow   = new Map(Types::Integer, Types::Record);
   mapMarkNow.insert(tmpInventTransMarkNow.RecId, tmpInventTransMarkNow);
   salesLineTrans.Qty = -1;
   TmpInventTransMark::updateTmpMark(salesLineTrans.InventTransId, inventDim, -salesLineTrans.Qty, mapMarkNow.pack());
   ttscommit;

}
***************************************

Complete Marking:
PurchLine   purchLine;
SalesLine   salesLine;
;
purchLine = PurchLine::findRecId(“464643344”);
salesLine =  SalesLine::findRecId(“2343464344”);

If (purchLine.RecId)
{
            purchLine.ItemRefType               = InventRefType::Sales;
            purchLine.InventRefId               = salesLine.SalesId;
            purchLine.InventRefTransId          = salesLine.InventTransId;
        purchLine.update();
}
        if (salesLine.RecId)
        {
            salesLine.InventRefType         = InventRefType::Purch;
            salesLine.InventRefId           = purchLine.PurchId;
            salesLine.InventRefTransId      = purchLine.InventTransId;

            salesLine.update();
        }

Friday, December 31, 2010

Create Workflow for Purchase Requisition and Create Purchase Order from Purchase Requisition in Dynamics AX 2009

Setup for Workflow
Basic à Setup à Settings for workflow. 

Please Click Validate to check that the website for workflow is working in good condition on IIS

Add caption


Administration à Setup à Batch groups
Please create a batch group “WF” to execute the batch processes for workflow.

Please assign a server, on which the workflow batch processes which run.

Administration à Setup àWorkflow infrastructure configuration





Basic à Batch Processing
Please start the batch process by clicking OK.

The batch process, will keep on searching if there is any Workflow related task to execute.


Basic à Inquiries à Batch Job
User can see which batch processes are running.

User can set the recurrence of the batch process.


Basic à Inquiries à Batch History
User can track the history of batch processes

Create Workflow for Purchase Requisition
Procedure: Select a Template and Name the Workflow
      To select a template, follow these steps:
  1. In the Accounts Payable, click Setup > Workflow configurations.

2.  On the Workflow configuration form, click New.


3.  The Create configuration: Select a template form is displayed. Select the template that the new workflow will be based on. Click Create configuration.


4.  The Workflow: <Workflow Name> form is displayed. Click the General tab.
5.  In the Name field, enter a unique name for the workflow.

Procedure: Enter Instructions for Users
Instructions can be provided to the users of the workflow. For example, for the purchase requisition workflow, use these steps to create the instructions for the users who will be submitting purchase requisitions for processing and approval in the Purchase requisitions form.
It is also possible to insert placeholders in the instructions that will be replaced with the appropriate data when the instructions are displayed to users.
  1. In the Workflow: <Workflow Name> form, click the General tab.
  2. Click Create instruction and the Edit message form is displayed.




































Create Purchase Order from Purchase Requisition: