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
 

Update NuGet package to new MS D365FO version

1. Import the NuGet package files from LCS for that particular version please take the PU version files only. a. Goto LCS-->Asset Libra...