Home > Dynamics Ax > Displaying the employee images on the EP pages of Dynamics Ax

Displaying the employee images on the EP pages of Dynamics Ax


In this example I am going to illustrate, displaying the employee images on EP pages.

Note: Assumed that all the images(photos) are mapped to their employee records by using Employee Details form in Ax client.

After the images are mapped to employee records, need to Publish the images in to sharepoint path by selecting the Publish images form, from Administartion à Setup àInternet àEnterprise Portal àPublish images  as shown in below figure and click on the Publish button of the form.

In this example, I am going to filter the records from Employee table, which employee is mapped to current user (logged in Ax user).

Development Steps

Step – I:

Prepare the Dataset for this example application by using the EmplTable and CompanyImage tables as shown in below figure.

Step – II:

Override the executeQuery method on the EmplTable of the above dataset.

This method for filtering the employee records from employee table, which employee is mapped to current user.

public void executeQuery()

{

    Query                   query = new Query();

    QueryBuildDataSource    qbs, qbs1;

    QueryBuildRange         qbr;

    QueryRun                qr;

    ;

 

    qbs = query.addDataSource(tablenum(EmplTable));

    qbs1 = qbs.addDataSource(tablenum(SysCompanyUserInfo));

 

    qbs1.addLink(fieldnum(EmplTable, EmplId), fieldnum(SysCompanyUserInfo, EmplId));

    qbr = qbs1.addRange(fieldnum(SysCompanyUserInfo, UserId));

    qbr.value(curuserId());

    qbr.status(RangeStatus::Hidden);

    qbs1.joinMode(joinmode::ExistsJoin);

    this.query(query);

    super();

}

 

Override the executeQuerymethod On the CompanyImage table of the above dataset.

The following method is used for filtering the Employee image(photo) from CompanyImage Table

public void executeQuery()

{

    Query                   q;

    QueryBuildDataSource    qB;

    QueryBuildRange         qbr;

 

    q = new Query();

    qB = q.addDataSource(tablenum(CompanyImage));

 

    qbr = qB.addRange(fieldnum(CompanyImage,RefCompanyId));

    qbr.value(queryValue(emplTable.company()));

    qbr.status(RangeStatus::Hidden);

 

    qbr = qB.addRange(fieldnum(CompanyImage,RefTableId));

    qbr.value(queryValue(emplTable.TableId));

    qbr.status(RangeStatus::Hidden);

 

    qbr = qB.addRange(fieldnum(CompanyImage,RefRecId));

    qbr.value(queryValue(emplTable.RecId));

    qbr.status(RangeStatus::Hidden);

 

    this.query(q);

 

    super();

}

 

Step – III:

Developing the required webpart for displaying the employee information and his image.

Markup Code for the UserEmployeeInfo webpart

<table>

<tr>

    <td valign="top">

                <asp:PlaceHolder ID="pnlImage" runat="server">

                    <table>

                        <tr>

                            <td>

                                <asp:Image ID="imgCompany" runat="server" />

                            </td>

                        </tr>

                    </table>

                </asp:PlaceHolder>

            </td>

</tr>

<tr>

<td>

<dynamics:AxGridView ID="AxGridView1" runat="server" DataKeyNames="RecId"

    DataMember="EmplTable" DataSourceID="UserEmployeeInfo">

    <Columns>

        <dynamics:AxBoundField DataField="name**" DataSet="UserEmplTableInfo"

            DataSetView="EmplTable">

        </dynamics:AxBoundField>

        <dynamics:AxBoundField DataField="Phone**" DataSet="UserEmplTableInfo"

            DataSetView="EmplTable">

        </dynamics:AxBoundField>

        <dynamics:AxBoundFieldGroup DataSet="UserEmplTableInfo" DataSetView="EmplTable"

            FieldGroup="Identification">

        </dynamics:AxBoundFieldGroup>

    </Columns>

</dynamics:AxGridView>

</td>

</tr>

</table>

C# (Code behind)Code for the UserEmployeeInfo webpart

using System;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using Microsoft.Dynamics.Framework.Portal.UI.WebControls;

using Microsoft.Dynamics.Framework.Portal.UI.WebControls.WebParts;

using Microsoft.Dynamics.Framework.Data.Ax;

using Microsoft.Dynamics.Framework.Metadata.Ax;

using Proxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;

using ApplicationProxy = Microsoft.Dynamics.Portal.Application.Proxy;

using Microsoft.Dynamics.Framework.BusinessConnector.Session;

using Microsoft.Dynamics.Framework.BusinessConnector.Adapter;

 

public partial class UserEmploeeInfo : System.Web.UI.UserControl

{

    #region Properties…

    /// <summary>

    /// Returns the current webpart

    /// </summary>

    private AxBaseWebPart WebPart

    {

        get { return AxBaseWebPart.GetWebpart(this); }

    }

 

    /// <summary>

    /// Returns the current webpart session

    /// </summary>

    private ISession AxSession

    {

        get

        {

            AxBaseWebPart webpart = AxBaseWebPart.GetWebpart(this);

            return webpart == null ? null : webpart.Session;

        }

    }

 

    //Enterprise portal images folder path

    string EPLayoutImagesPath

    {

        get { return "/_layouts/ep/images/"; }

    }

 

//reading the imagepath of the employee record from sharepoint

string GetImagePath(IAxaptaRecordAdapter record)

    {

        return this.EPLayoutImagesPath + ApplicationProxy.EPWebSiteParameters.companyImageFileName(AxSession.AxaptaAdapter, record);

    }

 

  

    #endregion

 

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!this.IsPostBack)

        {

            IAxaptaRecordAdapter row = UserEmployeeInfo.GetDataSourceView("CompanyImage").DataSetView.GetCurrent().GetRecord();

            imgCompany.ImageUrl = this.GetImagePath(row);

        }     

       

    }

}

 

Step – IV:

Add this newly developed user control to AOT and deploy this webpart on the sharepoint page. Open the newly created page url in the explorer and observe the result as follows. 

This is how employee images will be displayed on the EP pages of Dynamics Ax.  Red heart…… Rainbow

Advertisements
Categories: Dynamics Ax
  1. Hani
    December 15, 2009 at 6:38 pm

    It’s really more than excellent work Santosh, Thanks a lot for you great article and detailed tips.

  2. Santosh Kumar
    December 16, 2009 at 5:22 am

    u r most welcome Hani 🙂

  3. neeraj
    January 30, 2010 at 5:48 pm

    hey santosh, great work, keep it up and also keep sharing

  4. Santosh Kumar
    February 1, 2010 at 6:08 am

    Thanks Neeraj, Sure definitely….

  5. April 27, 2011 at 8:40 am

    Hello Santosh,
    there was in previous versions a sysimageaction.aspx script, which can be used as image source in the portal. so the image was shown directly from the database.

    in ax2009, i can use this script when using the ax webform, but with
    the ax usercontrol not…

    is there any way to show images in realtime out of the database?

    SebDra

  6. Radek Slovák
    May 4, 2012 at 12:48 pm

    Thanks you, that You helped me very much. 🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: