Saturday, January 28, 2012

Get and Set values implicitly in web control in EP

DataSetViewRow  row;

row = AxDatasource.GetDataSet().DataSetViews["DataSetViewName"].GetCurrentRecord();

// Get old value
row.GetFieldValue("FieldName");

// Set new value
row.BeginEdit();
row.SetFieldValue("FieldName", NewValue);
row.EndEdit();

Friday, January 27, 2012

Retrieving data from AX table in EP

Sometime we are in need of retrieving data from the tables which are not added in form's datasource in EP page. To manipulate the data from tables other than datasource (in EP) or dataset (in AX), following code will work.


Thursday, January 26, 2012

Microsoft Dynamics AX Code Samples

Here you can have the list of code sample of Microsoft Dynamics AX, AIF and EP

http://archive.msdn.microsoft.com/axcodesamples

How to: Test User Controls in Visual Studio [AX 2012]

It really made the process faster to test the user control without going to EP pages and refresh the AOD and data files again and again.
http://msdn.microsoft.com/en-us/library/cc616458.aspx

How to: Add Methods to Data Sets [AX 2012]

I found a very comprehensive article on MSDN about the subjected line of the post.

http://msdn.microsoft.com/en-us/library/ee677497.aspx

Hide Fields in a AxGroup /AxForm in Enterprise portal

There was a requirement to hide/un-hide the fields within AXGroup according to the setup defined in AX form either to show fields or not as per user.

protected void AxFrmEmployee_PreRender(object sender, EventArgs e)
{
    AxForm frm = this.axFrmEmployee;
   
    for (int i = 0; i < this.AxGroup1.Fields.Count; i++)
    {
        AxBoundField fld = this.AxGroup1.Fields[i] as AxBoundField;
        if ((fld != null) && (fld.Metadata.Name == "TitleId"))
        {
            fld.Visible = (frm.CurrentMode == DetailsViewMode.ReadOnly) ? false : true;
        }
    }
}

Accessing the URL of AxUrlMenuItem from AX into EP (Code behind)

Sometimes we need to change/append the URL defined on AXURLMenuitem in Dynamics AX 2012 in order to open different EP pages based on user selection. Here is the code to Create the complete URL in code (based On eb Menu Items)

     protected override void OnPreRender(EventArgs e)
    {       
        // Get the URL for the webpage that referenced the current record       
        AxUrlMenuItem url = new AxUrlMenuItem("EPSalesTableInfo");
       
        // update the hyperlink to point to the URL
        hpRecord.NavigateUrl = url.Url.ToString();

       // you can use this URL to redirect to any page like
       Response.Redirect(url.Url.ToString() + “&variable1=” +  stringvalue);       
    }

Monday, January 16, 2012

Making string field a custom lookup on user selection

Sometimes we just compile our posts to keep the things at one place so we or someone can get it easily when we in need. This post belongs to the same concept :)

Requirement was to filter the records in grid according to the selection of base enum values from a lookup. Easy task :) but then I had to make a string field a custom lookup on selection of first value from base enum and to make it a read only on selection of second value of the base enum.

This is what I did;

Filter: modified
public boolean modified()
{
    boolean ret;
    ret = super();

    if(str2enum(enum_variable,this.valueStr()) == enum::firstvalue)
    {
        stringField.allowEdit(true);
        stringField .text(' ');
    }
    else
    {
         stringField .allowEdit(False);
         stringField .text(curuserid());                
    }
    return ret;
}

StringEdit: StringField
// This lookup is populating users 
Public void lookup()
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    SysTableLookup          sysTableLookup;
    ;

    //Create an instance of SysTableLookup with the form control passed in
    sysTableLookup = SysTableLookup::newParameters(tablenum(UserInfo), this);

    //Add the fields to be shown in the lookup form
    sysTableLookup.addLookupfield(fieldnum(UserInfo, id), true);
    sysTableLookup.addLookupfield(fieldnum(UserInfo, name), false);

    //create the query datasource
    queryBuildDataSource = query.addDataSource(tablenum(UserInfo));
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(UserInfo, Id));
    queryBuildRange.value(element.getusers());

    //add the query to the lookup form
    sysTableLookup.parmQuery(query);

    // Perform lookup
    sysTableLookup.performFormLookup();
}

// Method to get users
str 100 getusers()
{    
    str 100                     Users;
    ;
    While Select UsersTable where  UsersTable .UserId == Curuserid()
    {
        Select Firstonly SysCompanyUserInfo where SysCompanyUserInfo.EmplId ==  UsersTable.Emplid ;
        Users+= SysCompanyUserInfo.UserId +',';
    }
    if(!Users)
        Return '\"\"' ;

    Return Users ;
}

Tuesday, January 10, 2012

How to configure and run AX 2012 Hyper-V on Virtualbox


I've found an interesting link about how to run AX 2012 VPC on Windows 7 without any need for Windows 2008 Hyper-V server installed on your machine.

Configuring and running the AX 2012 Hyper-V image with VirtualBox


Video

Saturday, January 7, 2012

.NET business connector to access Dynamics AX from .NET world

Few days before I was struggling to import the huge file data from excel into Dynamics AX as AX COM connector is not much powerful to import huge file data from excel. One of mine friends suggested me to go through .Net business connector to achieve the import functionality more quickly.

Here is the link which you can also find useful while integrating AX with different .Net based applications.
http://blogs.msdn.com/b/cesardelatorre/archive/2007/07/06/accessing-dynamics-ax-4-0-from-net-using-the-dynamics-ax-net-business-connector.aspx

Monday, January 2, 2012

Microsoft Dynamics AX workflow

I found a comprehensive blog describing the tips and tricks and code samples to implement workflow in your environment. 

I will be pleased to share it with all ; http://workflowax.wordpress.com/