Monday, November 27, 2017

Allowing IIS Application Pools to Access Local Folders

I was working recently with a client's ASP.Net application and had a requirement to log various items to a file log.  One of the issues was how to grant the correct user read/write permissions to folder in question.  This article explains how to grant folder permissions to the user running a given application pool.

https://docs.microsoft.com/en-us/iis/manage/configuring-security/application-pool-identities

Essentially, it involves granting "IIS AppPool\DefaultAppPool" or other application pool name (as defined in IIS) the appropriate permission.

Friday, November 17, 2017

D365 - Windows Server 2016 Datacenter Re-Activation

The Windows edition on my VM for client development expired.  It then started shutting down every 1/2 hour.  Needless to say this is quite annoying.

After some googling, I found that the evaluation edition of Windows can be re-armed.  The command to do this in the command prompt is:

slmgr.vbs -dli

If that doesn't work, try:
slmgr.vbs -rearm

https://organicax.com/2014/10/03/windows-rearm
https://support.microsoft.com/en-us/help/948472/how-to-extend-the-windows-server-2008-evaluation-period

The articles say that the extension is 60 days,  however my VM says 180.

Thursday, October 26, 2017

Decrypt Web.Config for D365

If you need to get into a D365 database that is located on a D365 VM.  The credentials are located under <install drive>:\aosservice\\webroot.  However, they are encrypted.  To decrypt them, you just need to run the following in a console window:

<install drive>::\AOSService\webroot\bin\Microsoft.Dynamics.AX.Framework.ConfigEncryptor.exe -decrypt <install drive>::\AOSService\webroot\web.config

Just make sure that you open the console as an administrator.  Normal users do not have access to the RSA keys.

Monday, October 2, 2017

Note to self...

Do not define string EDTs with length of 4000 characters.  Ax uses Unicode, so 2000 characters is 4000 bytes.  As a result, inserts will generate an Invalid Precision Value error in SQL Server.  Use a memo type instead.

https://community.dynamics.com/ax/f/33/t/177918


Tuesday, September 19, 2017

Ax 2012 - Queries and OData

Yesterday, I had an assignment to export a data table to Excel.  The current recommendations were to use either a list page or an SSRS report.  I had heard a number of references to OData, but did not know much about it.  It turns out that it was really easy to set up a feed.  Along the way, I learned something nice about AOT Query objects.

After a little reading, I found that any AOT Query object can be exposed as an OData Source.  My only issue was that the data that I needed came from a complex collection of tables (read unrolling dimensions again).  As a result, I decided to create an in-memory table and populate it using a stored procedure from the database.  That part was simple enough (just remember that the database calling method must be marked as server.

In general, I prefer to work with in-memory temp tables.  This is because tempDB is one of the busiest places in SQL Server.  From what I've gathered, every query that is executed against more that 1 table is resolved there.  So, the general advice is, if  you don't have to use tempDB, don't. 

The only issue that I had was how to use a query on using an empty temp table as a data source.  It turns out that AOT Query objects are based on QueryRun.  Literally, the class declaration reads:

public class QueryRun extends ObjectRun

So, to populate the query, all that you need is to call setCursor() on the init method.

public void init()
{
    super();
    this.setCursor(MyInMeomryTempTable::populate());
}


From there, exposing the Query was a simple matter of going to Organization Administration -> Setup -> Document Management and opening Document data sources.  Once there, simple add a new document data source.  The module is arbitrary and is just used for organizing the list of data sources.  Data Source Type needs to be Query Reference.  Then, select the name of the Query Object that you created and check Activated.  Description is optional.



Links: 
https://blogs.msdn.microsoft.com/aif/2011/08/23/odata-query-service/
http://immerhier.com/connect-microsoft-power-bi-to-ax-2012-odata-query-service/
http://www.uxceclipse.com/odata-powerquery-and-microsoft-dynamics-ax-2012-data-sources/


Friday, September 1, 2017

Dynamics 365 - Extending Sales and Purchase Documents

I almost got it right on my first attempt.  I was recently asked to update the PO Report in Dynamics 365.  In the extension model, a report is updated by doing the following:

  1. Create table extensions if extra data is required
  2. Create a copy of the report you wish to update
  3. Create a derived class of the controller that handles the report you are updating.
  4. Change the main method to point to the new report.
  5. Create a derived class of the Data Provider and override the processReport method to gather any new data required (don't forget to call super() to perform the original queries).
  6. Repoint the report's data sources to the derived data provider.
  7. Reformat the report as required.
  8. Extend all menu items that point to the original controller.  Repoint them to the new controller (object property).
  9. Compile the project, deploy the report and perform a synchronization.

In most cases, this is all that would be required to update an existing report.  However, the Purchasing and Sales Documents maintain a reference to the original document under print management.  So, even if you process the correct controller and data provider an you are point to the correct report; Dynamics 365 will return a blank report in the original format.

In order to define the correct default, you need to update the print management setting for the document type.  The process is the same for both Sales and Purchasing


Write a delegate that adds your extended report to the list of available reports for the document type.
public class CPPrintMgtDocTypeHandlersExt
{
    [SubscribesTo(classstr(PrintMgmtDocType), delegatestr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
    public static void getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {
        switch (_docType)
        {
            case PrintMgmtDocumentType::PurchaseOrderRequisition:
                _result.result(ssrsReportStr(CPPurchPurchaseOrder, Report));
                break;
        }
    }
}

In this case, an extended report is added to the Purchase Orders list.

Then set the report type as default for both the original and copy.  For Purchase Orders, go to Accounts Payable -> Setup -> Forms -> Form Setup. 





Then click Print management setup.  Once inside, select your document and right click.  Select New from the menu.  Fill in the other details and open the Report Format drop down.  If the delegate was set up correctly, then the new report format should appear.  Repeat these steps to add a default format for the copy as well.





Wednesday, August 30, 2017

Manually Add the Descriptor

Another task on this project had me update a label in the middle of a very large method that is called from 49 other places in D365.  Between changing 50 places in code as a set of derived classes and extensions or just customize the sys layer, I opted for the latter.  So, I created a customization project in a new model under ApplicationSuite.  The change took a few minutes.  I had to create new label files, write the labels, change the line of code.  I checked everything into VSTS correctly.  Then, a colleague did a test build and we found out that the new model that I created did not get registered by D365.  As a result, it could not be built from the Dynamics 365 menu.

A first pass at trying this had me export the project and emailing him the file.  My colleague then imported the file.  Then we found that the model was correctly created.  However, this did not seem like the right solution.

Contacting another colleague led me to the right solution.  Apparently, each model has a summary xml file under the Descriptor directory for the main model.  Customization models will have a file in the Descriptor folder of the model being customized (e.g. ApplicationSuite).  Extension models will have a Descriptor folder under the root (e.g. <<AosService>>\\PackagesLocalDirectory\<<Model Name>>.  In either case, the file for the descriptor needs to be manually added to VSTS.

Once a build machine gets the latest, the new model should be added.