Philippsen's Blog

Everyday findings in my world of .net and related stuff

Posts Tagged ‘Enterprise Portal’

Multiselection checkboxes in an AxGridview

Posted by Torben M. Philippsen on October 30, 2014

For a customer Ihad to fix a very non user friendly behavier in an AxGridview control.

The scenario was that they had an AxGridview control containing attachments in an expence module. For a single Expence you would one or more attachments – those attachments would be shown in the AxGridview when viewin the given expence post. In the gridview you would be able to select and deselect attachments but in the standard behavior the user flow would be something like this:

  1. Mark a row in the gridview – wait for postback to finish
  2. now the row is in edit mode – check the combobox – wait for postback
  3. click the update command button in the row – wait for poatback to finish

That’s a lot of waiting and posting back just to check a combobox. Ofcourse the customer wanted a more smooth solution.

My workaround was to try and create comboboxes that would be checkable but without posting back all the time. Doing this I had to consider how I would read the checked state from the comboboxes and persist the state to Ax/the underlying dataset. Here’s what I ended up with…

The markup

In order to have a combobox that is checkable at all times – not just in editmode, you will have to create a template field
EP_Multiselect_markup
Please notice that the AxGridview doesn’t allow paging and editing. Also you should notice that the combox doesn’t postback.

The first time the page loads checkboxes should be checked according to values from AX. Notice that the checked propety is handled by the Marked method

private Hashtable checkbox_values = new Hashtable();

    /// <summary>

    /// Method used in when each row is databound (See markup)

    /// </summary>

    /// <param name="dataItem"></param>

    /// <param name="container"></param>

    /// <returns></returns>

    protected bool Marked(object dataItem, object container)

    {

        AxGridViewRow gridViewRow = (AxGridViewRow)container;

        //CheckBox checkbox = (CheckBox)gridViewRow.FindControl("markCheckbox");

        DataSetViewRow row = dataItem as DataSetViewRow;

        if (row != null)

        {

            //string hashcode = checkbox.UniqueID;

            string hashcode = gridViewRow.RowIndex.ToString();

            if (this.checkbox_values.ContainsKey(hashcode))

            {

                //return row.Mark((bool)this.checkbox_values[hashcode]);

                return (bool)checkbox_values[hashcode];

            }           

        }

        return false;

    }

You will notice that the checked state depends on whether the current rows combobox has been added to a hashtable. The hashtable contains a boolean value for each rows combobox indicating whether it should be checked or not. The hashtable is populated on every postback like this:

 

   protected void Page_Load(object sender, EventArgs e)

    {

        getChecked(false);

 

 

//EG/2014.10.28/tomph, 00392460 XpenseAttachments –>

    /// <summary>

    /// Method used to fetch all marked checkboxes from the grid.

    /// This approach is used because we use a classic .net combobox with no postback (not an axboundfield)

    /// </summary>

    /// <param name="_saveToDataset">indicates whether this method is triggered from the save button click event or is just a normal postback</param>

    protected void getChecked(bool _saveToDataset)

    {

        foreach (GridViewRow row in AxGridView1.Rows)

        {

            if (row.RowType == DataControlRowType.DataRow)

            {

                CheckBox chk = (CheckBox)row.FindControl("markCheckbox");

                string hashcode = row.RowIndex.ToString();

                    if (chk.Checked)

                    {

                        if (!checkbox_values.ContainsKey(hashcode))

                        {

                            //only add if it does not exist

                            checkbox_values.Add(hashcode, true);

                        }

                        else

                        {

                            //update value if exists

                            checkbox_values[hashcode] = false;

                        }

                        if (_saveToDataset)

                        {      

                               //save the checked state to the datasat

                               DataSetView dsv = this.ImageDS.GetDataSourceView(this.AxGridView1.DataMember).DataSetView;

                               dsv.SetCurrent(row.RowIndex);

                               DataSetViewRow dsvr = dsv.GetCurrent();

                               dsvr.BeginEdit();

                               dsvr.SetFieldValue("selection**", 1);

                               dsvr.EndEdit();

                               this.AxGridView1.UpdateRow(row.RowIndex, false);

                        }

                    }

                    else

                    {

                        if (!checkbox_values.ContainsKey(hashcode))

                        {

                            //only add if it does not exist

                            checkbox_values.Add(hashcode, false);

                        }

                        else

                        {

                            //update value if exists

                            checkbox_values[hashcode] = false;

                        }

                        if (_saveToDataset)

                        {

                            //save the unchecked state to the datasat

                            DataSetView dsv = this.ImageDS.GetDataSourceView(this.AxGridView1.DataMember).DataSetView;

                            dsv.SetCurrent(row.RowIndex);

                            DataSetViewRow dsvr = dsv.GetCurrent();

                            dsvr.BeginEdit();

                            dsvr.SetFieldValue("selection**", 0);

                            dsvr.EndEdit();

                            this.AxGridView1.UpdateRow(row.RowIndex, false);

                        }

                    }               

            }

        }

    }

The only thing we will have to do know is to persist the checked comboboxes to the data, when clicking a “save/update” button. The save button click event calls the same method as above. Only difference is that the boolean value true is passed which again causes each row to be updated.

    protected void UpdateButton_Click(object sender, EventArgs e)

    {

        getChecked(true);

        this.ImageDS.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("updateSelections");

    }

Posted in Enterprise Portal Development | Tagged: , , , | Comments Off on Multiselection checkboxes in an AxGridview

Handling timeout issues on the EnterPrise Portal

Posted by Torben M. Philippsen on October 29, 2014

Lately I have been struggling with a timeout issue for a customer on the Enterprise Portal for Dynamics AX 2009.

I ended up doing two things – here are my experiences:

The problem:

If You have been working with EP, You have probably seen something like this on occasion
EP_TimeOut

The solution:

I will not claim to have a bulletproof solution but there are things that You might want to try

  1. In the AX client navigate to administration—>setup—>internet—>Enterprise Portal—>Parameters
    EP_parameters
    You could try to increase the values for timeout and history and see how that plays out for you.
  2. Another approach could be to increase the session timeout for the AX website in IIS. In order to do that you will have to do two things…
    Find the web.config file for your ax site. The path may look something similar to this C:\inetpub\wwwroot\wss\VirtualDirectories\80 – but ofcourse this may vary depending on your installation structure.
    In the configsections (in the top section of the web.config) you will have to add

    <sectionGroup name="Microsoft.Dynamics">
          <section name="Session" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.5000.0, Culture=neutral,PublicKeyToken=b77a5c561934e089" />
    </sectionGroup>

    EP_webConfig1
    Now scroll down and place the pointer after <system.web/> and before <runtime> and add

    <Microsoft.Dynamics>
        <Session Timeout="120" />
    </Microsoft.Dynamics>

    EP_webConfig2
    The session timeout is set in seconds and according to your needs.

    Good luck…

 

 

Thanks to my collegue Martin Lindhoff Lysgaard for input and assistance.

Posted in Enterprise Portal Development | Tagged: , , | Comments Off on Handling timeout issues on the EnterPrise Portal

How to debug x++ code from Enterprise Portal

Posted by Torben M. Philippsen on December 16, 2013

This article is mainly to support my own memory on how to configure things and being able to debug x++ code when executed from Enterprise portal (EP).

In order to being able to debug x++ executed from EP you need to follow these few steps:

  1. Log on to the server runnning the AOS
  2. Open the Microsoft Dynamics AX Server Configuration utility. To open Start –> Control Panel –> Administrative Tools –> Microsoft Dynamics AX 2009 Server Configuration.
  3. If you are not allowed to alter the existing configuration, create a new one that supports debugging.
    Click Manage then Create configuration. Give a name to the new configuration in the Create Configuration window then click OK

    On the Application Object Server tab, select Enable breakpoints to debug code X++ code running on this server. Click on Apply button.
    ServerConfiguration

  4. Click on the OK button to close the configuration window. You will get a message that indicates AOS is going to be restarted.’>Click on OK button to close the configuration window. You will get a message that indicates AOS is going to be restarted.
  5. Actually the debugger works on the server where IIS is running and Enterprise Portal is hosted. I used a single system and all the things are on the same system. If you are accessing a system remotely using Terminal Services then from the Start menu click Run. Type mstsc /consolein the Open text box and click OK
    This opens a console session in Terminal Services. Console session is required to debug Ax EP
  6. Open the Services window for the system. To open it Start –> Control Panel –> Administrative Tools –> Services.
    Right-click the World Wide Web Publishing Service and click Properties.
    Click the Log On tab
    Select Allow service to interact with desktop as shown below
    ServicesProperties
  7. Open the web.config file located in :\Inetpub\wwwroot\wss\VirtualDirectories\\, here the port number of the Enterprise Portal site. If you forgot the port then there is a way to check it out. Open Ax client then Administration main menu –> Setup –> Internet –> Enterprise Portal –> Web sites, here you can see the port
  8. Locate out the compilation element then set the debug attribute to true.
    Save the changes.
    Reset IIS (shouldn’t be necessary but I always do this just to make sure)
  9. Open the Microsoft Dynamics AX Configuration utility. To open it Start –> Control Panel –> Administrative Tools –> Microsoft Dynamics AX 2009 Configuration
  10. Set the Application Object Server Instance drop-down menu to Business Connector (non-interactive use only).
  11. If you are not allowed to alter the existing configuration, create a new one that supports debugging.
    Click on Manage button then click Create configuration. In the Create Configuration window, name the new configuration then click OK button.
    On the Developer tab, select Enable user breakpoints to debug code in the Business Connector and Enable global breakpoints to debug code running in the Business Connector or client then click on Apply button
  12. Click on OK button to close the configuration window
  13. Open the Microsoft Dynamics AX client
    On the Tools menu, click Options to display the Options window.
    On the Development tab, select When Breakpoint from the Debug mode list box, and then click Apply. This enables debugging mode on the client
    OptionsMenu
  14. Close the options window.
  15. Set the breakpoint of your choice in the x++ code
  16. Open the Debugger window manually. To open debugger manually click on Tools > Development Tools > Debugger
  17. Now execute the web form where the method has been invoked. It should work now and You should hit you breakpoint – nice:-)

Posted in Enterprise Portal Development | Tagged: , , | Comments Off on How to debug x++ code from Enterprise Portal

Enterprise Portal development (AX 2009) – the basics

Posted by Torben M. Philippsen on May 15, 2012

Sometimes I find myself struggling with a lot of basic stuff when wanting to do some EP related development. In order to spare me  (and hopefully others) some time in the future, I decided to create this article.

Step 1 – the prerequisites:

Generally You can save Yourself a lot of trouble if Enterprise Portal is installed on the same server as Your development environment (Visual Studio). If possible, You should also consider to have EP set up on a 32 bit platform – meaning that the OS and Windows Sharepoint Services (WSS) is running in 32 bit mode.

In matters of EP development, running on 64 bit platform is the mother of all evil – examples on this will follow…

Enterpise Portal development tools must be installed. This can be done from the installation medias.

Generally the EP dev tools installs EP project- and control templates. Please note that the EP dev tools should be installed after installing Visual Studio 2008 – if not, the VS templates will most likely not be installed correctly. To ensure that the EP dev tools are successfully installed and that the Dynamics AX web project template is available from within Visual Studio, please do the following:

The Web Site project template AxWebProject.zip is installed in My Documents folder under Visual Studio 2008\Templates\ProjectTemplates\Visual Web Developer\CSharp and page and control templates AxWebpartPage.zip and AxWebUserControl.zip under Visual Studio 2008 \Templates\ItemTemplates\Visual Web Developer\CSharp.

If these files are not found under Your user profile, You will have to copy them from the user who installed the EP dev tools.

The Add-in is installed in Program Files\Microsoft Dynamics AX\50\EnterprisePortalTools and is added to the VS Add-in files path and enabled.

  1. You can check this in VS Tools->Options->Environment->Add-in/macros security, you should see

    Visual Studio Options dialog

    Visual Studio Options dialog

  2. In VS Tools -> Add-In Manager Dynamics AX Enterprise Portal Tools must be enabled.

    Visual Studio Add In manager dialog

    Visual Studio Add In manager dialog

To check if everything is installed corrected, when you create a new Web Site Project in VS 2008 C#, you should see Dynamics AX Web project template. After creating the project, in the solution explorer when you right click on app_code folder you should get Generate Proxies menu option.

Reference article: http://blogs.msdn.com/b/solutions/archive/2008/08/09/ep-visual-studio-add-in.aspx

Once this has been verified everything is good to go, but before firing up Visual Studio, You should check in which layer VS connects to AX. VS uses the business connector when connecting to AX. This means that You have to check that the BC is connecting to the layer of Your choice. In my case, we always use the CUS layer. By default the BC connects to AX using the USR layer. If You want to change this do the following:

  • On the server where EP is installed, click the “Start” button in Windows. Select “administrative tools” and enter the “Microsoft Dynamics AX Configuration Utility”.
  • Change the “Configuration Target” to “Business Connector”.

Select the “Developer” tab and change the “Application object layer to open” to “CUS” (or whatever You want) Remember to fill in the license code for that layer

DAX Configuration utility

DAX 2009 Configuration utility

Step 2 – Understanding proxies:

In order to being able to reference common AX types (Objects from the AOT – Classes, tables, methods and enums) AX needs to generate proxies for the objects that You want to use. These objects are defined in the AOT from Web->Web files->Static files->proxies. If You want other objects to be recognized by EP and Visual Studio, You need to edit this file manually. A guide how to do that can be found here:
http://msdn.microsoft.com/en-us/library/cc568275(v=ax.50).aspx

To deploy the proxies to EP, please do the following:

  • From the Microsoft Dynamics AX menu click Tools -> Development Tools-> Web development -> Proxies.

In the “Generate Proxies” window You will find two options for deploying the proxies

DAX Generate Proxies Dialog

DAX Generate Proxies Dialog

Step 3 – Visual Studio

A new user control is easily created by right clicking Your project node and selecting “Add new item”. From the “Add new item” dialog choose “Dynamics AX user control

Visual Studio Add new item dialog

In order to add the new user control to the AOT. Right click the control and select “Add to AOT”.

Once added to the AOT changes to the control will automatically be submitted to AX. Once AX recognizes a change AX will update the control automatically on the EP site. However if running in 64 bit mode, this will not work! You can work around this in two ways:

  1. From a command prompt You can run the D:\Microsoft Dynamics AX\50\Setup\AxUpdatePortal.exe command. (The file may be located elsewhere in Your environment). Running this command will deploy all web related changes to all EP sites.
    http://msdn.microsoft.com/en-us/library/dd261467(v=ax.50).aspx
  2. Running the AXUpdatePortal command may be very timeconsuming. You may find it more useful to manually copy Your usercontrol  to Your EP site. The default path for the EP site is: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\ep. You may want to consider writing a small script to help You automate this process just a little bit.

Step 4 – Debugging in Visual Studio

Ofcourse You will want to be able to debug Your  code from within Visual Studio. In order to do so, there are a few things You need to know:

  • Changes made to your usercontrols are automatically updated at the EP site when running on a 32 bit platform. If running on a 64 bit platform, You will have to update EP manually. The process for doing so is described above.

You will have to change the debugging start options. Right click Your project and select “properties->Start options”. In the start options dialog enable the “start url” radio button:

Visual Studio Debugger Start Options

Visual Studio Debugger Start Options

and fill in the complete url for the page You want to hit on startup. This page is best found by browwing the actual EP site.
In the “use custom server” fill in the base url for the EP site. This can be fetched from within AX by entering  administration->Setup->Internet->Enterprise portal->web sites

Common issues

One of the most annoying things about working with EP related development is that You may quite often experience that EP causes Visual Studio to crash

EP Tools causes VS to crash

EP Tools causes VS to crash

The only working fix that I know of, is to create a new solution/website and have Your content transferred to that website. When the problem reoccurs the procedure has to be repeated – pretty annoying. If You know of a better workaround or maybe even a fix, please let me know.

Posted in Enterprise Portal Development, Microsoft Dynamics AX | Tagged: , , | 2 Comments »

 
%d bloggers like this: