Shrinking a Database Log file through SQL

Often our DB logs grow out of hand and we are left with limited space; a common occurrence on dev boxes for AX. So among other remedies to get more space is shrink your database log files and you can do so by using the queries below. Make sure you back up your databases before you run this, make this a standard practice before changing/modifying any meta on your db servers. You can do this for both your trans and model databases for Dynamics AX 2012.

USE DynamicsAXDev_model;

GO

— Truncate the log by changing the database recovery model to SIMPLE.

ALTER DATABASE DynamicsAXDev_model

SET RECOVERY SIMPLE;

GO

— Shrink the truncated log file to 1 MB.

DBCC SHRINKFILE (DynamicsAXDev_model_Log, 1);

GO

— Reset the database recovery model.

ALTER DATABASE DynamicsAXDev_model

SET RECOVERY FULL;

GO

AX Tables updated when a Pending Vendor Invoice is Posted inside #AX2012

An invoice when posted goes into the following tables:

For Invoice Header:

VendInvoiceJour defaults from VendInvoiceInfoTable

For Invoice lines:

VendInvoiceTrans defaults are from VendInvoiceInfoline table

See bttom to top:


Then a single record is inserted in VendTrans then VendTransOpen, see bottom to top

Change or Remove a dimension value on an Item through X++ in AX 2012

Using the below job you can update dimension values on an item.

</pre>

static void UpdateDepartmentMISC_Items(Args _args)
{

InventTable inventTable;
DimensionAttributeValueSetStorage dimStorage;
DimensionAttribute dimAttDept, dimAttMisc;
DimensionAttributeValue dimAttributeValueDept, dimAttributeValueMisc;

DataAreaId company;
str misc, dept;
ItemId itemId;
int counter = 0;

#define.DepartmentDimensionToUpdate('Department')
#define.MISCDimensionToUpdate('MISC')

info(strFmt('Start time: %1', time2StrHM(timeNow())));

changeCompany(company)

{

inventTable = null;

dimStorage = null;

dimAttMisc = null;

dimAttDept = null;

dimAttributeValueDept = null;

dimAttributeValueMisc = null;

while select forUpdate inventTable

where inventTable.ItemId == itemId

&& inventTable.dataAreaId == curext()

{

counter++;

try

{

ttsBegin;

dimStorage = DimensionAttributeValueSetStorage::find(inventTable.DefaultDimension);

dimAttDept = DimensionAttribute::findByName(#DepartmentDimensionToUpdate);

dimAttMisc = DimensionAttribute::findByName(#MISCDimensionToUpdate);

dimAttributeValueDept = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttDept, dept, true, true);

&nbsp;

if (misc)

{

dimAttributeValueMisc = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttMisc, misc, true, true);

dimStorage.addItem(dimAttributeValueMisc);

}

&nbsp;

dimStorage.removeDimensionAttributeValue(dimAttributeValueDept.RecId);

inventTable.DefaultDimension = dimStorage.save();

inventTable.doUpdate();

ttsCommit;

}

catch(Exception::Error)

{

error(strFmt("Error to update dimension for item %1", inventTable.itemid));

}

}

}

&nbsp;

info(strFmt("Records updated: %1", Counter));

info(strFmt('End time; %1', time2StrHMS(timeNow())));

}
<pre>

Tip for adding an element to an existing Base enum in AX 2012

Witnessed a scenario where an isv solution had modified an existing sys enum to add more values for its use and new elements value  was only increased by +1. This is a bad design practice and can cause issues further down the road when its time for an upgrade and Microsoft adds new elments to that enum so you do not want to be in that situation. Therefore the best practice is to add your element with a value that starts with +100.

So for example i have this ABC enum and its C element’s Enum value is 3:

enums.png

 

If my customization requires me to add values to this I should start at 103:

enums

This will prevent any future upgrade conflicts that can be a nightmare for someone doing an upgrade.

Destructive and Scripted Database Refresh

 

I’m often asked a question by customers on what we mean when saying we need a destructive refresh of the database or a scripted one for that matter. So here is a quick explanation.

 

A destructive refresh is basically make your environment be a copy of Another DB(Master, Prod, etc). In it I would take a backup of for example the Master DB and overwrite the DynamicsAX Trans DB.  Then I’d go in and change the pointers inside AX to point to your server instead of the Master server.

 

A scripted refresh keeps your pointers and some configurations, things like batch jobs and security, document handling and just copies most of the data from Master, going table by table.  Some tables are excluded in the scripted refresh, depending on what we are restoring.

 

Time taken: A destructive refresh will take about an hour to do, while a scripted refresh is 3-4 hours.

 

 

Resolving: Error System.InvalidOperationException: Unable to recycle AppPool ‘AOSService’ running Site ‘AOSService’.

Recently I came across an error while doing a complete build on D365

365poolerror

Error :

Severity Code Description Project File Line Suppression StateSeverity Code Description Project File Line Suppression StateError System.InvalidOperationException: Unable to recycle AppPool ‘AOSService’ running Site ‘AOSService’. Check your IIS/Azure Environment for correct deployment. —> System.Runtime.InteropServices.COMException: The object identifier does not represent a valid object. (Exception from HRESULT: 0x800710D8)   at Microsoft.Web.Administration.Interop.IAppHostMethodInstance.Execute()   at Microsoft.Web.Administration.ConfigurationElement.ExecuteMethod(String methodName)   at Microsoft.Web.Administration.ApplicationPool.Recycle()   at Microsoft.Dynamics.Framework.Tools.AosAppPoolRecycler.RecycleAppPool()   — End of inner exception stack trace —   at Microsoft.Dynamics.Framework.Tools.AosAppPoolRecycler.RecycleAppPool()   at Microsoft.Dynamics.Framework.Tools.BuildTasks.SyncEngineWrapper.Sync(CancellationToken cancellationToken) 0

Solution: 

To verify that an application pool has recycled correctly, follow these steps:

Open Internet Information Services (IIS) Manager as an administrator.

In Connections pane, expand your computer name.

Open Application Pools

Find the AOSService pool and if it is stopped, start it.

app pool

 

Resolving Visual studio tools 2013 installation error in AX 2012 R3 CU8

When trying to install visual studio tools the following error occurs “This installation package could not be opened. Verify that the package exists and that you can access it” This is mostly caused by VS tools folder missing inside the msi folder of your installation setup. If these folders are there then you might have a different issue. To resolve this for R3 builds follow the following blog by Microsoft support:

https://blogs.msdn.microsoft.com/axsupport/2015/04/21/how-to-slip-stream-ax-2012-r3-cu-8/

After this simply run your installer again and add the visual studio component, worked like a charm for me!

 

Time taken: 40mins

Transfer Demo data into AX 2012 R3

For transferring demo data into R3 versions of AX 2012 follow the below:

 

1 Get Demo data package and extract it into any feasible  location (Extraction will be large about 15-20GB)

 

Takes 20mins

https://mbs.microsoft.com/partnersource/northamerica/sales-marketing/demo-tools/virtual-machines/AX2012DemoToolsMaterialshttps://mbs2.microsoft.com/ecsts/login?signin=d2d9da3b041f6801aea3fcd9c858595d
2 Get Data transfer tool to transfer package extracted data in AX DB <<AX2012TestDataTransferTool.zip>>

https://lcs.dynamics.com/v2/LocalTools/

3 Import MetaDataXMLGenerator.xpo into AX environment and run the job

 

Take 30mins

This will be found in the Data transfer tools folder you extracted above
4 Copy Metadata file generated as output of the above job to the [Lists] folder in the Data Transfer tool directory File is mostly generated at the following path

 

C:\Users\mohsin.khalid\AppData\Local\Temp

 

 

5 STOP AOS before moving to the next step  
6 Open command prompt as admin. Go to directory where Test import tool was extracted.

Run the following command

 

Takes hours (2-3 approx.)

 

DP.exe IMPORT “C:\Users\mohsin.khalid\Downloads\MicrosoftDynamicsAXR3CU8DemoData” MicrosoftDynamicsAx

 

 

FYI; In above command “MicrosoftDynamicsAx” is your ax db name

 

 

 

  Total time of activity 4 hours approx