Showing posts with label Microsoft Dynamic AX 2012. Show all posts
Showing posts with label Microsoft Dynamic AX 2012. Show all posts

Friday, February 23

AX 2012: How to get Exchange Rate from sales Quotation Record.

There are many ways out there to find out the exchange rate of the current record in sales quotation form but below is the standard way to fetch the valid exchange rate amount with valid time frame.



static void GetSalesQuotationTableExhRate(Args _args)
{
    date      _date = systemDateGet();
    SalesQuotationTable tb = SalesQuotationTable::find("ISO-000081");
    CustExchRate    exchRate = 0;
    if (tb.SettleVoucher == SettlementType::SelectedTransact && SalesParameters::find().UseSettleExchRate)
    {
        exchRate = tb.settleExchRate(false);
    }
    if (!exchRate)
    {
        if (tb.FixedExchRate)
        {
            exchRate = tb.FixedExchRate;
        }
        else
        {
            exchRate = Currency::exchRate(tb.CurrencyCode, _date);
        }
    }
    info(strFmt("%3: %1 - %2",tb.CurrencyCode,exchRate/100,tb.QuotationId));
}

Monday, January 15

AX 2012 - How to get Vendor contact information in primary to default sequences

Get the Vendor telephone number from dirPartyContactInfoView



static void SL_GetVendorContactInformation(Args _args)
{
    dirPartyContactInfoView        dirPartyContactInfoView;
    VendTable       vendor;
    logisticsElectronicAddress logisticsElectronicAddress;
 
    vendor = VendTable::find("‪‪‪VEND-0000331‬‬");
    select firstOnly Locator from dirPartyContactInfoView
        order by dirPartyContactInfoView.IsPrimary desc
            where dirPartyContactInfoView.Party == vendor.Party &&
                  dirPartyContactInfoView.Type == LogisticsElectronicAddressMethodType::Phone;

   info(strFmt("Address is %1", dirPartyContactInfoView.Locator));

}

Monday, December 11

SSRS AX 2012 Error: Element ':PurchPurchaseOrder.Parameters.IsPurchConfirmationRequestJournal' has already been defined. To correct this, rename one or more of the model elements so that they have a unique name.

When we customize PurchPurchaseOrderReport to add a field on PurchPurchaseOrder Dataset in AOT and refresh dataset in Visual Studio.



We will get following error message:
Element':PurchPurchaseOrder.Parameters.IsPurchConfirmationRequestJournal’ has already been defined. To correct this, rename one or more of the model elements so that they have a unique name.


This is very common error and we can fix it by doing following steps: 
  1. Prior to refreshing Dataset, we have to rename the parameter IsPurchConfirmationRequestJournal to IsPurchConfirmationRequestJournalDelete
  2. Change the following properties:
    1. nullable – True
    2. allow blank – True
  3. Now refresh the dataset you should not see any errors and a new parameter IsPurchConfirmationRequestJournal will be created. Now set the below properties of new parameter:
    1. allow blank – True
    2. Nullable – True
  4. Once the properties are set, now delete the parameter ‘IsPurchConfirmationRequestJournalDelete’.
  5. Rebuild the solution and deploy the report.

Friday, November 3

AX 2012 - Different between AOT Table type (Regular , inMemory and Tempdb)

Different between AOT Table type (Regular , inMemory and Tempdb)

1: Regular: The default value. These are permanent tables.

2: InMemory: A temporary table that exists as an indexed sequential access method (ISAM) file.
The ISAM file can exist on either the client tier of the Application Object Server (AOS) tier.
The underlying Microsoft SQL Server has no connection to the ISAM file.
The system does allow you join an InMemory table in the X++ SQL syntax. However, joins and other set operations with InMemory tables are usually inefficient.
An InMemory table is the same thing as what was previously called a temporary table in Microsoft Dynamics AX 2009.


3: Tempdb: A temporary table that resides in the TempDB database of the underlying SQL Server.  The nonstandard format of a TempDB table causes the table to be dropped when it is no longer in use by the current method. Joins and other set operations on TempDB tables can be efficient.

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..

Friday, September 29

AX 2012: Forms - Row wise disable field based on other field value in grid

There are several ways to disable a field, but in many cases the whole column is disable. In these blog I am discussing about how to disable a field base on other field value.



Step 1:
First of all, you have to change the properties of your field in the form design, change the declaration property to YES.

Step 2: Go to Datasource in your form, select the field Datasource, in method override the active method and write you logic there.

For example:
In active method:

formfieldname.enable(datasourcename.fieldname > 3);

Whenever a record is active in a grid the above line base on condition update the form field.

Popular Posts