Tuesday, October 24

AX 2012 - Multi Table lookup - Display Fields from Multiple table in a lookup

Multi Table lookup - Where you can set lookup field from multiple table by joining multiple table and create a multi table lookup using SysMultiTableLookup. 

here is the Demo of the below code:




    Query                   query;
    QueryBuildDataSource    InventTrans;
    QueryBuildDataSource    GroupItem;
    QueryBuildDataSource    EcoRes;

    SysMultiTableLookup sysTableLookup;
    query = new Query();

    InventTrans = query.addDataSource(tableNum(InventTable));
    InventTrans.addRange(fieldNum(InventTable, SL_IncludeInSchemes)).value(queryValue(NoYes::Yes));

    //join the translation table so we can get a description of the UOM
    EcoRes = InventTrans.addDataSource(tableNum(EcoResProductTranslation));
    EcoRes.joinMode(JoinMode::InnerJoin);
    EcoRes.relations(false);
    EcoRes.addLink(fieldNum(InventTable,Product),fieldNum(EcoResProductTranslation,Product));

    //join the translation table so we can get a description of the UOM
    GroupItem = InventTrans.addDataSource(tableNum(InventItemGroupItem));
    GroupItem.joinMode(JoinMode::InnerJoin);
    GroupItem.relations(false);
    GroupItem.addLink(fieldNum(InventTable,ItemId),fieldNum(InventItemGroupItem,ItemId));
    GroupItem.addLink(fieldNum(InventTable,DataAreaId),fieldNum(InventItemGroupItem,ItemDataAreaId));

    //filter by the unit class being passed
    GroupItem.addRange(fieldNum(InventItemGroupItem, ItemGroupId)).value(queryValue(smmParametersTable::find().SL_SchemeReleaseItemGroup));

    //define multiple table lookup query
    sysTableLookup  = SysMultiTableLookup::newParameters(_formControl, query);
    //add which fields will be displayed to the user (symbol + desc.)
    sysTableLookup.addLookupfield(fieldNum(InventTable, ItemId), true);
    sysTableLookup.addLookupfield(fieldNum(EcoResProductTranslation, Name), 2);
    //do not use for multi table
    //sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();

Monday, October 23

AX 2012 - Get User Roles Associated with current user in X++ code

Following line of code fetch all roles associated with current login user in microsoft dynamics ax 2012.



static void Getuserroles(Args _args)
{
    SecurityRole role;
    SecurityUserRole userRole;
    UserInfo userInfo;
    ;
    while select role
        exists join userRole
            where role.RecId == userRole.SecurityRole &&
                       userRole.User == curUserId()
    {
        info(strFmt(“%1 – %2”, role.Name,curUserId()));
    }
}

Monday, October 9

AX 2012 - preRunModifyContract Method in controller class example

Here is an example for a preRunModifyContract method in which it simply fetch the PurchTable record and set the RecId in the contract class.

Function:

/// <summary>
/// Fetch the <c>PurchTable</c> record.
/// </summary>
/// <returns>
/// set <c>Contract</c> class for selected record recid.
/// </returns>
protected void preRunModifyContract()
{
    PurchTable                    PurchTable;
    LandCostContract           contract;

    contract = this.parmReportContract().parmRdpContract() as LandCostContract;
    PurchTable = this.parmArgs().record();

    contract.parmRecId(PurchTable.RecId);
}

AX 2012 - Calculating the hash Value of a string in X++ code

There is infinite number of ways how to compute a hash and, of course, different implementations and different hash algorithms have different properties. Below code is the most simplest code for generating a hash value of a string in SHA-256. you can update this code and provide your own hashing algorithm by editing the below line with the list of available hashing algorithm in MSDN.

System.Security.Cryptography.SHA512::Create();



Hashing Function:

public str CalculateHash(str tb)
{

    str s;
    ClrObject obj;
    ClrObject SHA256;
    System.Text.StringBuilder sBuilder;
    ClrObject clrStr;
    ClrObject clrStrObject;
    System.Exception clrException;
    System.Array resultByteArray;
    int i;
    int arrayLength ;
    InteropPermission perm;

    perm = new InteropPermission(InteropKind::ClrInterop);
    perm.assert();
    try
    {
        obj = System.Text.Encoding::get_ASCII().GetBytes(tb);
        SHA256 = System.Security.Cryptography.SHA512::Create();
        resultByteArray = SHA256.ComputeHash(obj);
        //BP deviation documented
        sBuilder = new System.Text.StringBuilder();
        arrayLength = resultByteArray.get_Length() ;
        // Loop through each byte of the hashed data
        // and format each one as a hexadecimal string.
        for (i = 0; i <arrayLength; i++)
        {
            clrStrObject = resultByteArray.GetValue(i);
            clrStr = clrStrObject.ToString('x2');
            sBuilder.Append(clrStr);
        }

        // Return the hexadecimal string.
        s = sBuilder.ToString();
    }
    catch (Exception::CLRError)
    {
        //BP deviation documented
        clrException = CLRInterop::getLastException();
        s = clrException.get_Message();
        error(s);
        throw error("@SYS106158");
    }

    CodeAccessPermission::revertAssert();
    return s;

}

Friday, October 6

AX 2012 - Difference between Form Methods , Form Data source Methods , Table Level Methods

1. Form methods can be overridden so as to change the behavior of the form in response to user interface events, and customize the appearance of a form

2. Form datasource methods can be overriden so as to change the behavior for validation, caching etc eg initvalue() can be used to fill in default values when creating a new record

3. Table methods is where most of processing codes should be placed instead of on form datasource methods. This can be overridden eg validateField() to validate a value in a field




See the below links for details:

Table Methods [AX 2012]

Methods on a Form [AX 2012]

Methods on a Form Data Source [AX 2012]


For this blog specially Thanks to robsmusau,

Thursday, October 5

SSRS Report - Can't see changes after deploying SSRS report AX 2012

Follow the following steps:
  1. If you are on R3, you have the Tools -> Caches -> Refresh report server;
  2. Also, do a Tools -> Caches -> Refresh elements and Tools -> Caches -> Refresh dictionary;
  3. If you have an AOT query, you can do a Restore on the query;
  4. Open the report in Visual Studio, and perform a Refresh on your dataset in the Datasets node;
  5. Also in Visual Studio perform a rebuild and a deploy of the report;
  6. Before step 5. you can check that the parameters you have for your report are the proper ones (if you've changed the data contract or the query);
  7. Depending on the decision to load the last values (controller.parmLoadFromSysLastValue) you want to do a Reset usage data;
  8. And last but not least, you want to do a Restore and then also a Deploy element on the report in the AOT.
If your still facing the issue then finally restart your SQL Server Reporting Services in service and run the report.

OR

sometimes you need to delete the report in the report document folder, then deploy again to get the latest version published. After that restart the SSRS service instance.

I hope that one of these helps.

Using AXBuild Command for Parallel Compilation of AOS in Microsoft Dynamics AX 2012

We can compile AOS direct from the development environment by Right click on AOS then compile, but it usually takes up to 4 to 6 hours depending upon your systems support. The direct method of compiling AOS takes much longer time, which may paralyze your work for hours.

So here comes a trick to compile AOS much faster than ever by AXBuild command which hardly takes up to 15 to 17 mins to compile the AOS. Before running the command, the following are the key steps to follow:

Step 1 - Go to Windows Search, type Services. Click on Service. Go to Microsoft Dynamics AX Object Service and stop the Dynamic AX Object service for a while before running the command.


Step 2 - Go to windows search, type cmd and open it as an administrator



Step 3 - Change your location to the Microsoft Dynamics AX bin folder. Just copy and paste below comment in cmd.

"C:\Program Files\Microsoft Dynamics AX\60\Server\TAVSP\bin"



Step 4 - Enter the below command to run a full compile on AOT in cmd

"axbuild.exe  xppcompileall  /s=01 /altbin="C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin"


Note: After this multiple cmd are open which will run in parallel to compile different parts of AOT, to increase your parallelism you can add /w=03 in above command to increase number of threads.




Step 5 - For error logo cmd will show a location where all the error are write to file.


Step 6 - Go to the file location show in the command prompt and open the respective file for your purpose.







AX 2012 - Multi Table Lookup - Join many multi with root table to display a lookup on root table

Lookup table on form datasource field. Here is the code for multi table look.



public void lookup(FormControl _formControl, str _filterStr)
{
    Query                                query           = new Query();
    QueryRun                         QueryRun;
    QueryBuildDataSource    reasoncode;
    QueryBuildDataSource    inventTransWMS;
    SysTableLookup               sysTableLookup;
    ;

    super(_formControl, _filterStr);


    if(TmpInventTransWMS.InventQty < 0)
    {
        reasoncode  = query.addDataSource(tableNum(SL_TransferOrderReasonCode));

//<tag>Repeat<tag>
        inventTransWMS = reasoncode.addDataSource(tableNum(SL_InventTransWMS));
        inventTransWMS.fetchMode(JoinMode::ExistsJoin);

        inventTransWMS.relations(false);
        inventTransWMS.addLink(fieldNum(SL_TransferOrderReasonCode, Code),fieldNum(SL_InventTransWMS, SL_TransferOrderReasonCode));

        inventTransWMS.addRange(fieldNum(SL_InventTransWMS, InventDim)).value(queryValue(TmpInventTransWMS.InventDimId));
        inventTransWMS.addRange(fieldNum(SL_InventTransWMS, InventTransOrigin)).value(queryValue(InventTrans::findRecId(TmpInventTransWMS.InventTrans).InventTransOrigin));
        inventTransWMS.addRange(fieldNum(SL_InventTransWMS, InventTransOrigin)).value(queryValue(InventTrans::findRecId(TmpInventTransWMS.InventTrans).InventTransOrigin));

//you can add more data set by repeat from <tag>repeat</tag> tag.

        sysTableLookup = SysTableLookup::newParameters(tableNum(SL_TransferOrderReasonCode), _formControl);
        sysTableLookup.addLookupfield(fieldNum(SL_TransferOrderReasonCode, code));
        sysTableLookup.addLookupfield(fieldNum(SL_TransferOrderReasonCode, codeDescription));

        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }
}

Wednesday, October 4

AX 2012 - How to change the capture of form at runtime in X++

There are certain requirement in which we have to change the name of form based on certain field value, the below line can be inserted in any method where you want like active, init etc...



//field condition
if (condition)
{
       element.design().caption('New Label');
}

hope this will help you..

Popular Posts