How to open AX with a User Role and debug it at the same time in Dynamics #AX2012

Recently came across a scenario where we had to debug a user session that had limited rights to the system, one way of doing that could be for instance walking through a trace of the user session and another would be to debug code while user steps through the process but that would be done only for server side calls. So what if we need to debug client side calls as well, how to go about doing that was the challenge. Since if we assign the user role to an admin and execute the process we also have admin privileges which are higher up the ladder and do not limit access to what that user role has. Not to worry there is a way you can do this by following the steps below:

1. Run Dynamics AX as an administrator
2. Add the role you want to debug to your own user, let the Sys Admin role stay as well.
3. Open a new development Work space.
4. Place breakpoints where you need them.
5. Create below job
static void NonAdmin(Args _args)
{
securityutil::sysadminmode(false);
}
7. Execute the above job
8. Open a new workspace
9. Run the process you wanted to debug.

You should now be able to hit the break point you placed in Microsoft Dynamics AX 2012 Debugger as the User role.

P.s I found this thanks to an old post by a colleague of mine.

 

Advertisement

Solution: Cant see w3wp.exe process to attach for debugging #D365 code

 

If you are unbale to find the w3wp.exe process that we attach our VS debugger to inorder to step through X++ on D365. Chances are the windows logging service is not running. The service name to check is W3C Logging Service start this service by going to services.msc and reopen/refresh the process list.

 

P.s Also make sure your World Wide Web Publishing service is running. Without which your D365 client wont be hosted as well.

For more details on how to debug D365 have a look at the MS blog: Quick and easy debugging in AX 7

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>

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

Debugging without a startup project or startup Object in D365

To debug without setting up a startup project and startup object in D365 fotr operations. Follow these steps:

  1. Open your object in visual studio
  2. Place breakpoints
  3. Goto Debug>attach to process and check show processes from all users
  4. Select w3wp.exe and click attach.

DebugWithoutStartupObject

You can execute your process now from the client and execution will be stopped at your breakpoints.

 

How to Recall/Cancel a workflow through code in AX 2012

To recall a workflow through code you can use the cancelworkflow method in workflow class. It takes the correlationId and a comment as parameters and gets the job done for you. Example

workflow::cancelworkflow(CorrelationId, “Cancelling this workflow”)

Now you are probably thinking How do I find my workflows CorrelationId. You can do that by querying WorkflowTrackingStatusTable sorting it with time and instance number and joining it with SysWorkflowtable against the correlationId field and in the contextId you pass the RecId of your record for example PO RecId.

Fix for Error: Field ‘Company’ and ‘Lot ID’ must be filled in”

When editing a PO line for procurement category you receive Field ‘Company’ and ‘Lot ID’ must be filled in” error. This usually happens when you have brought in the PO line through some form of integration either AIF, excel plugin etc.

This error has also been seen on salesLine and there is a hotfix(KB 2756645) for when it happens on salesline.

Error

Reason:

There is no record in PurchLineForeignTradeCategory table related to PO line added.

 

Solution:

Create a record against the PO line causing this error in the PurchLineFroeignTradeCategory table in your integration and you will see the error disappear.