Wednesday, 8 October 2014

Display method filter in AX 2012

http://dynamicsaxsolutionsworld.blogspot.no/2011/09/how-to-add-search-find-filter.html

This is for my reference and got it from above site.

How to add Search/ Find /Filter functionality to Display method in dynamics AX
Dynamics AX, can retrieve output values by using table field and display method. As we know, usually standard dynamics AX filter functionality is working only for table field. But sometimes we have to do filter functionality for display method too. Below I’m going to explain how to add a filter functionality for Display method.

1.      Here I have added display method (disCustName) to display customer name on the “IND_BusRelation” form. In this form main data source is “smmBusRelTable”.

2.      Change “AutoDeclaration” property from No to Yes of the “disCustName” data field.
3.      Override “context()” method of the “disCustName” data field and add following code.
  
public void context()
{
    int             selectedMenu;
    formrun         fr;
    Args            ag;
    Name            strtext;
    querybuilddataSource qb1;
    queryrun    qr;
    query       q;
    PopupMenu menu = new PopupMenu(element.hWnd());
    int a = menu.insertItem('Filter By Field');
    int b = menu.insertItem('Filter By Selection');
    int c = menu.insertItem('Remove Filter');
    ;

    selectedMenu = menu.draw();
    switch (selectedMenu)
    {
    case -1: //Filter by field
            break;
    case a:
            ag = new args('SysformSearch');
            fr = new formrun(ag);
            fr.run();
            fr.wait();
//Reading User entered value for filter process
            strtext = fr.design().controlName('FindEdit').valueStr(); 
            if(strtext)
            {
//Creating a query for filter
                q   = smmBusRelTable_ds.query();
                qb1 = q.dataSourceTable(tablenum(smmBusRelTable));
                qb1 = qb1.addDataSource(TableNum(CustTable));
                qb1.addLink(FieldNum(smmBusRelTable,CustAccount),FieldNum(CustTable,AccountNum));
                qb1.addRange(FieldNum(CustTable,Name)).value(strtext);
                smmBusRelTable_ds.query(Q);
                smmBusRelTable_ds.executeQuery();
            }
            break;

    case b:   // Filter By Selection
            q   = smmBusRelTable_ds.query();
            qb1 = q.dataSourceTable(tablenum(smmBusRelTable));
            qb1 = qb1.addDataSource(TableNum(CustTable));
            qb1.addLink(FieldNum(smmBusRelTable,CustAccount),FieldNum(CustTable,AccountNum));
            qb1.addRange(FieldNum(CustTable,Name)).value(disCustName.valueStr());
            smmBusRelTable_ds.query(Q);
            smmBusRelTable_ds.executeQuery();
            break;
    case c :   // Remove Filter
            q   = new Query();
            qb1 = q.addDataSource(tablenum(smmBusRelTable));
            qb1.clearLinks();
            qb1.clearRanges();
            smmBusRelTable_ds.query(Q);
            smmBusRelTable_ds.removeFilter();
            break;

    Default:
            break;
    }

}

4.       Run the form and do right Click on Customer Name field.


 

Wednesday, 1 October 2014

Debug user control (Visual Studio) in EP

IN Enterprise Portal.


Debugging in the ASP.NET Development Server Environment

--------------------------------------------------------------------------------


To debug a User Control in the ASP.NET Development Server environment, you must create a Dynamics AX Webpart Page that will run the User Control. For more information, see How to: Test User Controls in Visual Studio.
To debug in the ASP.NET Development Server environment

1. Start Visual Studio.

2. Open the EP Web Application project that contains the User Control that you want to debug.

3. View the code for the User Control. Do this by right-clicking the User Control in Solution Explorer, and then clicking View Code.

4. Add breakpoints to the appropriate locations in the code.

5. In the Debug menu, click Start Debugging.

6. In the web browser window that is displayed, click the file name for the Dynamics AX Webpart page (.aspx) that contains the User Control that you want to debug. Visual Studio should stop execution at the designated breakpoints.



Debugging in Enterprise Portal

--------------------------------------------------------------------------------


To debug a User Control that is running in Enterprise Portal, you must enable debugging for the Enterprise Portal web site, and then configure your EP Web Application project for debugging.
To enable debugging for the Enterprise Portal web site

1. On the system that is running Enterprise Portal, locate the web.config file for the Enterprise Portal site. Typically, this found in C:\inetpub\wwwroot\wss\VirtualDirectories\80\. If you are running Enterprise Portal on a port other than 80, the web.config file will be found in a folder with that number.

2. Use a text editor such as Notepad to edit the web.config file.

3. Search for the node that is named compilation. Set the debug attribute for this node to true.



Copy



ImportantImportant

We do not recommend that you enable debugging in production environments for Enterprise Portal.


4. Save the changes to the web.config file.

To debug in Enterprise Portal

1. Start Visual Studio. If User Account Control (UAC) is active, be sure you start Visual Studio with administrative privileges.

2. Start Enterprise Portal.

3. Open the EP Web Application project that you want to use for debugging.

4. In the Debug menu in Visual Studio, choose Options and Settings. Expand the Debugging group and select General. Be sure that Require source files to exactly match the original version is not marked. Click OK.

5. Add the User Control to the EP Web Application project.

6. If the User Control uses any proxies to access X++ code, add the needed proxy projects to the solution in Visual Studio. To add a proxy project, click the Project menu, choose Add EP Proxy Project. Select the proxy project and click OK. The EPApplicationProxies project is the most frequently used proxy project.

7. Attach the Visual Studio debugger to the process for Enterprise Portal. In the Debug menu, click Attach to Process.

8. Click Select to specify the type of code you want to attach to. Mark Managed (v2.0, v1.1, v1.0), and then click OK.

9. Mark the Show processes from all users and Show processes in all sessions to be sure that all processes are being displayed.

10. In the Available Processes list, select the w3wp.exe process that is being used for Enterprise Portal. If there are multiple processes with that name, the values in the Type and User Name columns may help you determine which is the process being used for Enterprise Portal. If you cannot determine which process is being used, select all of the w3wp.exe processes.

11. Click Attach to attach the Visual Studio debugger to the selected processes.

12. View the code for the User Control. Do this by right-clicking the User Control in Solution Explorer, and then clicking View Code.

13. Add breakpoints to the appropriate locations in the code.

14. In Enterprise Portal, navigate to the page that contains the User Control that you want to debug. When the breakpoints you set are encountered, the Visual Studio debugger should stop execution at the designated breakpoints.
 

EP: C# Code to capture mouse click event on AXGridView / Code to get the cell index on AXGidView

EP: C# Code to capture mouse click event on AXGridView / Code to get the cell index on AXGidView


-----we need to write the code in page render method-----

protected override void Render(HtmlTextWriter writer)
    {
        // Ensure that the control is nested in a server form.
        if (Page != null)
        {
            Page.VerifyRenderingInServerForm(this);
        }
        #region Code for mouse click event
        
         //Add the extras to each row.
        foreach (GridViewRow row in AxGridView2.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                // Show hand like the mouseover of buttons. (Not very functional, but very cute.)
                //row.Attributes["onmouseover"] = "this.style.cursor='pointer';";
               
                // Each Cell will need its own PostBack link, with the necessary information in it.
                foreach (TableCell cell in row.Cells)
                {
                    if (row.Cells.GetCellIndex(cell) >= 8) // click to apply only for cell index > 8
                    {
                        // Although we already know this should be the case,
                        // make safe code. Makes copying for reuse a lot easier.
                        if (cell is DataControlFieldCell)
                        {
                            // Put the link on the cell.
                            cell.Attributes["onclick"] =
                                Page.ClientScript.GetPostBackClientHyperlink(AxGridView2,
                                String.Format("CellSelect${0},{1}", row.RowIndex, row.Cells.GetCellIndex(cell)));
                            // Register for event validation: This will keep ASP from giving nasty errors from
                            // getting events from controls that shouldn't be sending any.
                            //Page.ClientScript.RegisterForEventValidation(AxGridView2.UniqueID,
                            //    String.Format("CellSelect${0},{1}", row.RowIndex, row.Cells.GetCellIndex(cell)));    
                        }
                    }
                }
            }
        }
        #endregion Code for mouse click event
        base.Render(writer);
    }

-----Now Add the RowCommand method for the AXGridview-----

///
    ///
    ///

    string selectedCellDate;
    ///
    /// To get selected cell index
    ///

    ///
    ///
    protected void AxGridView2_RowCommand(object sender, GridViewCommandEventArgs e)
    {       
        #region
        this.DisplayMatrix();
        // Don't interfere with other commands.
        // We may not have any now, but this is another safe-code strategy.
        if (e.CommandName == "CellSelect")
        {
            // Unpack the arguments.
            String[] arguments = ((String)e.CommandArgument).Split(new char[] { ',' });
            // More safe coding: Don't assume there are at least 2 arguments.
            // (And ignore when there are more.)
            if (arguments.Length >= 2)
            {
                // And even more safe coding: Don't assume the arguments are proper int values.
                int rowIndex = -1, cellIndex = -1;
                int.TryParse(arguments[0], out rowIndex);
                int.TryParse(arguments[1], out cellIndex);
                // Use the rowIndex to select the Row, like Select would do.
                // ...with safety: Don't assume GridView2 even has the row.
                if (rowIndex > -1 && rowIndex < AxGridView2.Rows.Count)
                {
                    AxGridView2.SelectedIndex = rowIndex;
                }
                if (cellIndex >= 8)
                {
                    selectedCellDate = this.ConvertToDateTime(txtFromDate.Text).AddDays(cellIndex - 8).ToString();
                    this.GetRelatedOrders(chkboxProductCategory.Checked, selectedCellDate);
                }
            }
           
        }       
        #endregion       
       
    }
    #endregion
 

Thursday, 5 June 2014

Installing Dynamics AX 2012 R3

Installing Dynamics AX 2012 R3
Prerequisites:
1. Windows Server 2012 R2
2. Microsoft visual studio 2012 + SP1
3. Microsoft SQL Server Enterprise Edition + SP1
4. Microsoft office 2013
5. Microsoft project 2013
------------------------------------------------------------------------------------------------------------
Now let's start installing Wish you good luck.
--> Log on to Windows Server 2012 with Admin user
1. Go to Active directory --> user and computers
Ø  Service Accounts --> Add new Group
Ø  Add below users
o   SSAS
o   SQLDB
o   SSRS
o   AXAOS (AOS Admin)
o   AXBCP (Business connecter)
o   AXWKFL (Work flow)
§  To add user Rt click on Service Accounts + new
§  Give Full name
§  user name
§  password (please note the password, as we need it in coming process)
§  check the box (Password never expire)
Ø  Add above users to Group
Ø  Give Administrator permission to the above group.

2. SQL Server Configuration Manager
Ø  SQL Server (MSSQL Server)
Ø  Properties
Ø  Change Account to "SQLDB" the one which we created in previous step.
3. Now Go to Microsoft Dynamics AX2012 R3 setup file and run as Administrator
ü  Select option Single Computer
ü  Data base
ü  AOS
ü  click next.
ü  Give the Domain and user name (AXAOS)
ü  Click Finish.
ü  Now install Client components.
ü  Click Next --> Next --... Finish.
Now you are done with AX AOS and Client.
4. Lunch AX Run--> ax32

compile the application and finish the check list. 

Wednesday, 4 June 2014

EP: DataSetLookup issue with sysDataSetLookup.parmQuery(query)

EP: DataSetLookup issue with sysDataSetLookup.parmQuery(query)

Recently I have faced a strange issue in Dataset lookup method and come to know that there is come issue with " sysDataSetLookup.parmQuery(query) " when it is called from EP.

The actual issue was, when we pass the query as parameter to the method  " sysDataSetLookup.parmQuery(query) ", the query range are not applied and it will fetch all the records without any query filter. It is a strange issue and happens inconsistently.

And I could make out solution for the about issue.
we need to add the range at the end instead of passing it as a parameter, as shown below.

Actual dataset Lookup method:
void dataSetLookup(SysDataSetLookup sysDataSetLookup)
{
    QueryBuildDataSource qbd;
    QueryBuildRange qbr;
   
    List list = new List(Types::String);
    Query query = new Query();

    // Add the table to the query.
    query.addDataSource(tableNum(FCMRooms));

    // Specify the fields to use for the lookup.
    list.addEnd(fieldStr(FCMRooms,RoomName));
    list.addEnd(fieldStr(FCMRooms,RoomType));
    list.addEnd(fieldStr(FCMRooms,InService));

    // Supply the set of lookup fields.
    sysDataSetLookup.parmLookupFields(list);

    // Specify the field that is returned from the lookup.
    sysDataSetLookup.parmSelectField('RoomName');
       
    // Add range
    qbd = query.addDataSource(TableNum(CustTable));
 
    qbr = qbd.addRange(FieldNum(CustTable, AccountNum));
    qbr.value(">=4000"); // Default operator is ==.

    // Pass the query to the SysDataSetLookup so that the query is used.
    sysDataSetLookup.parmQuery(query);
}
Modified  dataSetLookup method:
void dataSetLookup(SysDataSetLookup sysDataSetLookup)
{
    QueryBuildDataSource qbd;
    QueryBuildRange qbr;
   
    List list = new List(Types::String);
    Query query = new Query();

    // Add the table to the query.
    query.addDataSource(tableNum(FCMRooms));

    // Specify the fields to use for the lookup.
    list.addEnd(fieldStr(FCMRooms,RoomName));
    list.addEnd(fieldStr(FCMRooms,RoomType));
    list.addEnd(fieldStr(FCMRooms,InService));

    // Supply the set of lookup fields.
    sysDataSetLookup.parmLookupFields(list);

    // Specify the field that is returned from the lookup.
    sysDataSetLookup.parmSelectField('RoomName');
       
    // Add range
    qbd = query.addDataSource(TableNum(CustTable));
 
    qbr = qbd.addRange(FieldNum(CustTable, AccountNum));
    qbr.value(">=4000"); // Default operator is ==.

    // Pass the query to the SysDataSetLookup so that the query is used.
    sysDataSetLookup.parmQuery().addDataSource(TableNum(CustTable)). value(">=4000");
}



Hope this helps .. Happy Learning.

Wednesday, 21 May 2014

EP: Export data in enterprise portal page to excel (Dynamic)


Hello every oneJ!

This article is to export data in enterprise portal page to excel (Dynamic) :

 

In the recent time we have faced an issue while we tried to export data to excel using dynamic option. For your information there are two ways to export data 1. Static and 2. Dynamic (Differences we are not going to discuss in this article).

The data was not coming into excel we can see only columns headings in the first line.

(In Dynamic excel export the business log will run from the local client and the data is fetched from AOS)

This is due to settings on the Microsoft Excel à Dynamics AXàOptions
 



Here the Server name and Port should be the same as your AOS server name and port respectively.

Hence by changes these settings our issue got resolved. Hope this will help youJ!

Monday, 21 April 2014

Resolving Ctrl+F5 Error on creation of Item Master in AX2012.

Solution for Ctrl+F5 Error on creation of Item Master in AX2012.

Error: Cannot edit a record in Items(InventTable).
The values displayed in the form are not current, so an update or deletion

cannot be made. To view the current values, on the command menu, click
Restore or press CTRL+F5.

As the error message says, this error is due to an update conflict. when we
try to update the master data in some business process and this call is from
the form, the rec-version on the form is different from the current
rec-version in DB. Hence system will throw error.

To resolve this kind of issues, we need to refresh and reread the calling
formDataSource.


Here is the code.

// NS by Mallik 10/04/2014
    FormRun         formRun;
    FormObjectSet   formObjSet;
    int             i;
    InventTable     linventTable;
// NE by Mallik 10/04/2014
// NS by Mallik 10/04/2014
    // refresh and reread inventTable datasource if exists in form
    if (this.isFormDataSource())
    {
        formRun = this.dataSource().formRun();
        for (i=1; i<= formRun.dataSourceCount(); i++)
        {
            if (formRun.dataSource(i).cursor() is InventTable)
            {
                formObjSet = formRun.dataSource(i);
                linventTable = formObjSet.cursor() as InventTable;
                break;
            }
        }
        if (!linventTable)
        {
            linventTable = InventTable::find(this.ItemId, true);
        }
        if (linventTable)
        {
            if (formObjSet)
            {
                formObjSet.refresh();
                formObjSet.reread();
            }
        }
    }
// NE  by Mallik 10/04/2014

Wednesday, 5 March 2014

AIF related jobs to send XML and Process Inbound and OutBound.

As the name indicate, this job is used to send the XML (Out bound).
static void SendElectronically(Args _args)
{
    AxdSendContext      axdSendContext  = AxdSendContext::construct();
    AifEntityKey        aifEntityKey    = AifEntityKey::construct();
    Map                 keyData;
    AifConstraintList   aifConstraintList   = new AifConstraintList();
    AifConstraint       aifConstraint       = new AifConstraint();
    LedgerJournalTable  ledgerJournalTable;
    //PurchTable          purchTable;
    CustInvoiceJour     custinvoiceJour;
    ;
    //select firstOnly purchTable
        //where purchTable.purchid == "PO-0000013";
    while select custinvoiceJour
        order by InvoiceId
        where custinvoiceJour.SalesId == "0000005"
    {
    keyData = SysDictTable::getKeyData(custinvoiceJour);
    aifEntityKey.parmTableId(custinvoiceJour.TableId);
    aifEntityKey.parmRecId(custinvoiceJour.RecId);
    aifEntityKey.parmKeyDataMap(keyData);
    axdSendContext.parmXMLDocPurpose(XMLDocPurpose::Original);
    axdSendContext.parmSecurity(false);
    aifConstraint.parmType(AifConstraintType::NoConstraint) ;
    aifConstraintList.addConstraint(aifConstraint) ;
    AifSendService::submitDefault(  classnum(AvaSalesInvoiceTransService),
                                    aifEntityKey,
                                    aifConstraintList,
                                    AifSendMode::Async,
                                    axdSendContext.pack());
    }
}

-----------------------------------------------------------------------------------------------------------
This job is used to process AIF Inbound
static void aifInboundJob()
{
    new AifGatewayReceiveService().run();
    new AifInboundProcessingService().run();
}
-------------------------------------------------------------------------------------------------------------
This job is used to process AIF Outbound
static void aifOutboundJob()
{
    new AifOutboundProcessingService().run();
    new AifGatewaySendService().run();
}
--------------------------------------------------------------------------------------------------------------

static void AifSetupMainBatchJobs(Args _args)
{
    #AvaAif
    BatchJob    batchJob;
    Batch       batch;
    if(!BatchJob::existAvaCaption(#AIF+"2"))
    {
        ttsBegin;
        //create batch job
        batchJob.initValue();
        batchJob.Caption            = #AIF+"2";
        batchJob.OrigStartDateTime  = DateTimeUtil::getSystemDateTime();
        batchJob.Status             = BatchStatus::Waiting;
        batchJob.insert();
        //create AIF receive service task
        batch.initFromClass(new AifGatewayReceiveService());
        batch.Caption               = #AifGatewayReceiveServiceCaption;
        batch.BatchJobId            = batchJob.RecId;
        batch.Status                = BatchStatus::Waiting;
        batch.RunType               = BatchRunType::Server;
        batch.Company               = curext();
        batch.insert();
        //create AIF send service task
        batch.initFromClass(new AifGatewaySendService());
        batch.Caption               = #AifGatewaySendServiceCaption;
        batch.BatchJobId            = batchJob.RecId;
        batch.Status                = BatchStatus::Waiting;
        batch.RunType               = BatchRunType::Server;
        batch.Company               = curext();
        batch.insert();
        //create AIF inbound service task
        batch.initFromClass(new AifInboundProcessingService());
        batch.Caption               = #AifInboundProcessingServiceCaption;
        batch.BatchJobId            = batchJob.RecId;
        batch.Status                = BatchStatus::Waiting;
        batch.RunType               = BatchRunType::Server;
        batch.Company               = curext();
        batch.insert();
        //create AIF outbound service task
        batch.initFromClass(new AifOutboundProcessingService());
        batch.Caption               = #AifOutboundProcessingServiceCaption;
        batch.BatchJobId            = batchJob.RecId;
        batch.Status                = BatchStatus::Waiting;
        batch.RunType               = BatchRunType::Server;
        batch.Company               = curext();
        batch.insert();
        //start the batch job
        ttsCommit;
    }
}
 

Import and Export file from BLOB storage Account(Azure) in D365 F&O using X++

  Import and Export file from BLOB storage Account in D365 F&O using X++ Import: /// <summary> /// MKInventQualityOrderLineService...