June 17, 2013

Use resource files in Axapta

Use resource files in Axapta

In Application Object Tree, you can find resources node.
Select resources node and right click; select Create from File, specify the file location for the new resource file. After that you can use this resource file in Axapta without specifying an absolute file path in your local/server system.

First, pick up the resource node from AOT;


SysResource::getResourceNode();

Then generate a temporary file for this resource file;

SysResource::saveToTempFile()

Finally specify the temporary file path for controls.
Here comes an example to show how to use a resource file as a background image of  a given form.

{
ResourceNode            resourceNode;
FilePath  imagename;
;
resourceNode = SysResource::getResourceNode(resourcestr(ResourceName));
if (resourceNode)
{
resourceNode. AOTload();
imagename =  SysResource::saveToTempFile(resourceNode);
}
else
{
throw Error(“No file exists.”)
}

element.design().imageName(imagename);
}

You can try This also
Add a resource file in Resource node under AOT, Right click on Resource Node -> select "Create From File"



Select a file  from your your local drive.



 You can change the label and name of this file as require.














To use this image file in your code just add following code 

SysResource::getResourceNodeData(SysResource::getResourceNode('theaxapta_File'));

Enjoy.......

-Harry

June 13, 2013

Conditional Joins in x++

Conditional Joins in x++
Here is the code to apply joins conditionally in Microsoft Dynamics AX.

query = new Query();
dsInventTable = query.addDataSource(tableNum(InventTable), "InventTable");
dsInventItemBarCode = dsInventTable.addDataSource(tableNum(InventItemBarCode), "InventItemBarCode");
dsInventItemBarCode.joinMode(JoinMode::ExistsJoin);
// Add any two ranges
queryBuildRange1 = dsInventTable.addRange(fieldNum(InventTable, DataAreaId));
queryBuildRange2 = dsInventItemBarCode.addRange(fieldNum(InventItemBarCode, DataAreaId));

Find all records where either the ItemType is Service, or the ItemType is Item and a barcode exists. The join criteria is only applied in the second half of the expression, so all Service items will appear irrespective of whether they have a bar code. Again, this is not possible to achieve using the standard query ranges.

queryBuildRange2.value(strFmt('((%1.%2 == %3) || ((%1.%2 == %4) && (%1.%5 == %6)))',
query.dataSourceTable(tableNum(InventTable)).name(), // InventTable %1
fieldStr(InventTable, ItemType), // ItemType %2
any2int(ItemType::Service), // %3
any2int(ItemType::Item), // %4
fieldStr(InventTable, ItemId), // ItemId %5
fieldStr(InventItemBarCode, ItemId))); // %

-Harry

June 08, 2013

Generate Next Number Sequence by x++ code





Generate Next Number Sequence by x++ code

When we create a new record from user interface(by using Forms) number sequence handles automatically by system. But Some time we need to assign a number sequence by code, like we create numbers of records by code and in this case we have to take care of number sequence. 
Here a job to create next number from a number sequence by x++ code.

static void theaxapta_Nextnumseq(Args _args)
{
         NumberSeq num;
         
DiscountTable  _DiscountTable; //Table Buffer
        ;
        ttsbegin;
           num = NumberSeq::newGetNum(HrmParameters::numRefJournalNum()); // Parameters Table
          
_DiscountTable.NextNumseq = num.num(); // Next NumberSeq generated
          
_DiscountTable.insert();
          num.used(); // Mark the Number as Used
      ttscommit;
}



//The other Way is by using EDT

static void testnumseq(Args _args)
{
     theaxaptaEDT   _
theaxaptaEDT   ;
     ExtendedTypeId id = TypeID2ExtendedTypeId(TypeId(theaxaptaEDT));//EDT NAME
     NumberSeq num = NumberSeq::newGetNum(NumberSequenceReference::find(id));
     ;
     //
_theaxaptaEDT.NextNumseq = num.num();//NEXT NUM SEQ
     num.used(); // mark the number as used
     info(num.num()); // NEXT NUM SEQ
}


-Harry

June 06, 2013

Changed, and Deprecated Features for Microsoft Dynamics AX 2012

Hi Folk,

As we all know, there are many new changes came in AX2012 and many few are depreciated from earlier version. Recently while searching over internet i come across one book that will provide all such information. Below is the link to download this book.

New, Changed, and Deprecated Features for Microsoft Dynamics AX 2012, available for download here.

-Harry