Wednesday, 22 May 2013

EP: Create code a Lookup and apply filter (in Visual C#) with two joined tables

EP: Create code a Lookup and apply filter (in Visual C#) with two joined tables

Here In this example, I want to display the records, from EcoResCategory Table for the fields Name and Code.
 
Here I am filtering the records which have, CategoryHierarchy 
EcoResCategoryHierarchyRole.CategoryHierarchy == EcoResCategoryHierarchy.RecId
 
 #region Code to ProductCategory lookup
    //ProductCategory Lookyp
    ///
    /// ProductCategory Lookup event handle method, this method will get Product from EcoResCatogory.
    ///

    ///
    ///
    protected void ProductCatLookup_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup lookup = e.LookupControl;
        int EcoResCategoryId = TableMetadata.TableNum(this.AxSession, "EcoResCategory");
        //Create the lookup dataset � we will do a lookup in the EcoResCategory table
        using (Proxy.SysDataSetBuilder dataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(AxaptaAdapter, TableMetadata.TableNum(EcoResCategoryLookupTableName)))
        {
            // Set the run time generated data set as the lookup data set
            lookup.LookupDataSet = new DataSet(AxSession, dataSetBuilder.toDataSet());
        }
        lookup.LookupDataSet.Init();
        using (Proxy.Query query = lookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
        {
            using (Proxy.QueryBuildDataSource dataSource = query.dataSourceName("EcoResCategory"))
            {
                TableMetadata EcoResCategoryMetadata = MetadataCache.GetTableMetadata(this.AxSession, EcoResCategoryId);
                TableDataFieldMetadata categoryHierarchyField =(TableDataFieldMetadata)EcoResCategoryMetadata.Fields.GetByName("CategoryHierarchy");
                //TableDataFieldMetadata nameField = (TableDataFieldMetadata)EcoResCategoryMetadata.Fields.GetByName("Name");
                
                using (Proxy.QueryBuildRange range = dataSource.addRange(categoryHierarchyField.FieldId))
                {
                    range.status = (int)Proxy.RangeStatus.Open;
                    range.value = Convert.ToString(this.GetEcoResCategoryHierarchyRoleByRole());                  
                }
            }
        }
        lookup.Fields.Add(AxBoundFieldFactory.Create(ProductCatLookup.LookupDataSetViewMetadata.ViewFields["Name"]));
        lookup.Fields.Add(AxBoundFieldFactory.Create(ProductCatLookup.LookupDataSetViewMetadata.ViewFields["Code"]));
        lookup.SelectField = "RecId";
        lookup.HideSelectField = true;
        RequisitionerRecId.Text = string.Empty;
        RequisitionerName.Text = string.Empty;
        this.EnabledDisableItemId(false);
        this.EnableDisableProductCat(true);
       
    }
 
///
    /// ProductCatogory on ok click event handel method, this mehod will assign RecID to ProductCategoryRecID text box.
    ///

    ///
    ///
    protected void ProductCatLookup_OnOkClicked(object sender, AxLookupEventArgs e)
    {
        string recIdValue = ProductCategoryRecID.Text;
        long recId = 0;


        if (recIdValue == null ||
            recIdValue.Length <= 0 ||
            recIdValue == "0" ||
            long.TryParse(recIdValue, out recId) == false)
        {
            ProductCategoryRecID.Text = string.Empty;
            ProductCategoryName.Text = string.Empty;
        }
        else
        {
            ProductCategoryName.Text = GetProductCategoryFromRecId(recId);
        }
    }

   
    private string GetProductCategoryFromRecId(long recId)
    {
        //string ProductNamel;
        using (AppProxy.EcoResCategory lEcoResCategory = AppProxy.EcoResCategory.find(recId))
        {
            ProductNamel = lEcoResCategory.Name;
        }

        return ProductNamel;
    }

    protected long GetEcoResCategoryHierarchyRoleByRole() // call Table method EcoResCategoryHierarchyRole getHierarchiesByRole
    {

        using (AppProxy.EcoResCategoryHierarchyRole lEcoResCategoryHierarchy = AppProxy.EcoResCategoryHierarchyRole.avaFindHierarchiesByRole(SalesCat))
        {
            ecoResCategoryHierarchyrecId = lEcoResCategoryHierarchy.CategoryHierarchy;
        }
        return ecoResCategoryHierarchyrecId;
    }
   

AX 2012 Compile error in Web Control after you added a new method(proxies) in AX to use in Visual Studio

You can run into issue when you have the object method (from class, table) which is already used by proxy. During development you decide to add a new method or change the parameters of the existing method.
After you move to Visual Studio, the proxy will be regenerated and new method/ new parameter will be available, so you can use it without any problem when developing your Web Control. Such a Web Control you will be able to compile without any issue in Visual Studio.
The problem happens when you decide to compile it in Dynamics AX Development environment. Usually when you use one of the Source Control method in Version Control > System settings usually you have setup to Reject Compile errors to be sure of integrity of checked in code.
The problem happens when you try to check in Web Control which is using freshly added method (parameter) then you get compilation error like:
Compile error: \CatDisplayProductDetail.ascx.cs(251): error CS0117: 'Microsoft.Dynamics.Portal.Application.Proxy.CatCartLine' does not contain a definition for 'method1'
 The issue happens because the proxies which are used to compiled in Dynamics AX are not regenerated to fix the problem you can:
  1.  Before compile you need to right click on AOT \ Web \Web Files \ Web controls and select “Generate Proxies for Compilation”
 
    2.       What we can also go is in \Classes\SysEPWebControlCompiler\ensureDependencies:

//generate dependencies if the existing version of dependencies is not same as current version
            if(System.IO.File::Exists(versionFilePath))
            {
                dependencyVersion = System.IO.File::ReadAllText(versionFilePath);
            }
            if(dependencyVersion != currentVersion)
            {
                this.generateDependencies();
                System.IO.File::WriteAllText(versionFilePath, currentVersion);
            }
            canCompile = true;
we can comment the line if (dependencyVersion != currentVersion) then every time when you compile web control he will update dependencies. The problem here is that it takes some time  even those you did not change any proxies, so we can have some performance degradation.
 

Friday, 29 March 2013

EP AX2012: Data source metadata error > Unable to logon to Microsoft Dynamica AX

You will encounter this type of error from Enterprise portal, when you try to add AX data set to Dynamics AX user control.




Root cause: The root cause of this issue is “The WSDL Port and/or TCP/IP port number “is not matching with Enterprise portal WSDL / TCP IP port number.



Resolution:

Step1: Check the server configuration on EP server.

Step2: Map the same configuration on the local client.



Hope this will help… Best of luck.-- Mallik

Wednesday, 20 March 2013

Setup Debugger in EP & Debug X++ Code on EP Pages

X++ code can be used in various resources that are accessed by a page, such as tables, data sets, and classes. You can debug X++ code for elements that are accessed by pages by using the debugger for Microsoft Dynamics AX. You can debug Enterprise Portal code only on the system that is running Internet Information Services (IIS).
To set up X++ debugging for pages


1. Log into the server that is running the AOS.

2. Open the Microsoft Dynamics AX Server Configuration utility with administrative privileges (Start > Administrative Tools > Microsoft Dynamics AX 2012 Server Configuration). To run the utility with administrative privileges, you must right-click its icon in the Start menu and choose Run as administrator.

3. Create a new configuration that allows debugging.

1. Click Manage and then click Create configuration. In the Create Configuration window, name the new configuration, such as "DAX Debugging". Click OK.

2. On the Application Object Server tab, select Enable breakpoints to debug code X++ code running on this server. Click Apply. If you receive a message about the AOS, indicate that it should be restarted.

4. Click OK to close the configuration window.

5. Log in to the server that is running IIS and Enterprise Portal. If the system is remote, you can do this using a Remote Desktop Connection. From the Start menu, click Run. Type the following in the Open box and then click OK:

mstsc /console

This opens a console session in Remote Desktop.

6. Enable desktop interaction for the World Wide Web Publish Service.

1. Open the Services window for the system (Start > Administrative Tools > Services).

2. Right-click the World Wide Web Publishing Service, and then click Properties.

3. Click the Log On tab.

4. Select Allow service to interact with desktop.

5. Click OK to close the properties window.

7. Open the web.config file located in \Inetpub\wwwroot\wss\VirtualDirectories\\, where is the port number of the site where Enterprise Portal is installed. Modify the file by doing the following:

1. Locate the compilation element, and then set the debug attribute to true. This reduces the chance of the Web session having a time-out error when it is stopped at a breakpoint.

2. Save the changes.

8. Reset IIS by typing the iisreset command at the command-line window that has been started with administrative privileges.

9. Open the Microsoft Dynamics AX Configuration utility with administrative privileges (Start > Administrative Tools > Microsoft Dynamics AX 2012 Configuration). To run the utility with administrative privileges, you must right-click its icon in the Start menu and choose Run as administrator.

10. Set the Configuration Target drop-down menu to Business Connector (non-interactive use only).

11. Create a new configuration that allows debugging.

1. Click Manage and then click Create configuration. In the Create Configuration window, name the new configuration, such as "DAX Debugging". Click OK.

2. On the Developer tab, select Enable user breakpoints to debug code running in the Business Connector. Click Apply.

12. Click OK to close the configuration window.

13. Open the Microsoft Dynamics AX client with administrative privileges. To do this, you must right-click on the icon for Microsoft Dynamics AX and then choose Run as administrator.

14. Open the Development Workspace.

15. On the Tools menu, click Options to display the Options window.

16. Click the Development link. In the Debug area, select When Breakpoint from the Debug mode list box. This enables debugging mode on the client.

17. Close the Options window.

To debug X++ code from a Web page
 1. Log in to the server that is running Internet Information Services (IIS) and Enterprise Portal. If the system is remote, you can do this using a Remote Desktop Connection. From the Start menu, click Run. Type the following in the Open box and then click OK:


mstsc /console

This opens a console session in Remote Desktop, and is necessary if you want to debug on a remote system.

Note:If you are debugging on a remote system, you must use console mode when connecting. Otherwise, debugging will not work.

2. Open the Microsoft Dynamics AX client with administrative privileges. To do this, you must right-click on the icon for Microsoft Dynamics AX and then choose Run as administrator.

3. Be sure that you are logged on as a user who is also the following:

o The user who started the session of Microsoft Dynamics AX

o The user who will set breakpoints in X++ code

o A member of the Microsoft Dynamics AX Debugging Users local group on Windows

4. Open the Development Workspace.

5. In the AOT, locate the element that you want to debug. Typically, you will debug data sets, tables, or classes.

6. Set breakpoints in the X++ code by using the Code Editor.

7. Open the debugger by clicking Tools, and then clicking Debugger. The Debugger must be open before you can run code that contains breakpoints.

8. Open the Web page that accesses the element that you want to debug. As the page is rendered, the Debugger should stop at the breakpoints that you set.

Monday, 9 July 2012

Tree node to Excel file

static void CreateExcelMallik(Args _args)


{



SysExcelApplication xlsApplication;

SysExcelWorkBooks xlsWorkBookCollection;

SysExcelWorkBook xlsWorkBook;

SysExcelWorkSheets xlsWorkSheetCollection;

SysExcelWorkSheet xlsWorkSheet;

SysExcelRange xlsRange;

AsciiIO tmpfile;

Filename tmpfilename;

FileIOPermission permission;

TreeNode treeNode;

TreeNode treeNodeTables;

#File

#AOT

int row = 1;

str fileName;

;



treeNodeTables = TreeNode::findNode(#SecurityKeysPath);



// Name of the Excel document.



fileName = "C:\\test.xsl";



// Excel open and initialize.



xlsApplication = SysExcelApplication::construct();

xlsApplication.visible(true); //Generate new Excel worksheet.

xlsWorkBookCollection = xlsApplication.workbooks();

xlsWorkBook = xlsWorkBookCollection.add();

xlsWorkSheetCollection = xlsWorkBook.worksheets();

xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);

// Write headlines cells in the worksheet.

xlsWorkSheet.cells().item(row,1).value('Name'); xlsWorkSheet.cells().item(row,2).value('ID');

row++;

// first table

treeNode = treeNodeTables.AOTfirstChild();

// Excel worksheet with fill data (Excel fill-cells).

while (treeNode != null)

{

xlsWorkSheet.cells().item(row,1).value(treeNode.AOTname()); xlsWorkSheet.cells().item(row,2).value(treeNode.applObjectId());

row++; // next table

treeNode = treeNode.AOTnextSibling();

}

// Check whether the document already exists.

if(WinApi::fileExists(fileName))

{

WinApi::deleteFile(fileName);

}

// Excel document store.

xlsWorkbook.saveAs(fileName);

//Close Excel.

xlsApplication.quit(); xlsApplication.finalize();

}

Tree Node for Security Key and write to text file.

static void TextFile_TreeNood_Demo(Args _args)


{

AsciiIO tmpfile;

Filename tmpfilename;

FileIOPermission permission;

#File

#AOT

TreeNode treeNode;

TreeNode treeNodeTables = TreeNode::findNode(#SecurityKeysPath);

tmpfilename = WinApi::getTempFilename(WinAPI::getTempPath(),'SecurityKey');

permission = new FileIOPermission(tmpfilename,#IO_write);

permission.assert();

tmpfile = new AsciiIO(tmpfilename, #IO_write);

if(tmpfile.status()==IO_Status::Ok)

{

tmpfile.outRecordDelimiter('\n');

tmpfile.outFieldDelimiter(';');

}

else

{

return;

}



while (treeNode != null)

{

tmpfile.write(strfmt('Name: %1, ID: %2',treeNode.AOTname(), treeNode.applObjectId())); /

}

tmpfile = null;

CodeAccessPermission::revertAssert();

}

AIF Test JOB

static void AIFTesting(Args _args) { AifGatewayReceiveService AifGatewayReceiveService; AifInboundProcessingService AifInboundProcessingService; ; AifGatewayReceiveService = new AifGatewayReceiveService(); AifInboundProcessingService = new AifInboundProcessingService(); AifGatewayReceiveService.run(); AifInboundProcessingService.run(); //ttsabort; }

How to Get Trade Agreement Line Discount Percentage by Item and Date in D365FO Using X++

  In Microsoft Dynamics 365 Finance and Operations (D365FO), trade agreements are used to manage prices and discounts for customers, vendor...