Tuesday, October 8, 2019

D365 Do not disable form controls - disable the datasource fields!

When developing forms in Microsoft Dynamics 365 for Operations you sometimes want to disallow the user to edit some of the forms fields. The typical approach is to turn on Auto Declaration on the form controls and diasable them using:
FormControl.allowEdit(false);

The problem with this approach is that the same field might be exposed more than once in your design, for instance both in the grid view and in the details view. Also, users adding fields via Personalization might pose challenges. In order to make sure the user is not allowed to edit the data, use this approach:
Datasource_ds.object(fieldNum(tablename, fieldname)).allowEdit(false);

Similarly you can enable/disable the fields if this is your business requirement. This will make it more evident for the user that the field is not editable:
Datasource_ds.object(fieldNum(tablename, fieldname)).enabled(false);

Wednesday, November 18, 2015

Domain role with multiplicity 0..1 or 1 can hold at most 1 link


I got the following error when I duplicate a SSRS report in Visual Studio:
Domain role with multiplicity 0..1 or 1 can hold at most 1 link: DataSetParameter of Microsoft.Dynamics.Framework.Design.Model.Reports.DataSetParameterRefersToParameter.

To resolve it do the following on the report datasets:
  1. Change the datasource type to Query.
  2. Delete the whole query text in the "Query" field.
  3. Save, rebuild and change the values on the datasource back to the ones intended
Thanks to AlexDAX for this tip!

I also noticed the above actions can help resolve other problems, like inconsistency in the report parameters (can occur if you change the contract parameters).

Wednesday, December 18, 2013

Cancel salesline in x++ code (including CW)

Cancelling an open salesline through code is a simple task.
When you're operating with catch weight items you need to include the CW remainder field.

The following code will cancel all open lines on a sales order that has been invoiced.
Don't forget tts.

    while select forupdate salesLine
    join salesTable
        where   salesTable.SalesId == "[Your SO]"
        &&      salesTable.SalesStatus == SalesStatus::Backorder
        &&      salesTable.DocumentStatus == DocumentStatus::Invoice
        &&      salesLine.SalesStatus == SalesStatus::Backorder
    {
        salesLine.RemainInventPhysical = 0;
        salesLine.RemainSalesPhysical = 0;
        salesLine.PdsCWRemainInventPhysical = 0;
        salesLine.Update();
    }


Friday, November 8, 2013

Parameter _reportName cannot be null or empty.

Recently came over a problem with running SSRS reports from AX 2012 (R2). This infolog error message was presented immediately when trying to run a report:

Parameter _reportName cannot be null or empty.
The [CLASSNAME].[METHODNAME]() reflection API could not create and return the SrsReportNameAttribute object.

In this specific case it looks like an earlier full compile did not finish.

If you encounter this problem I would suggest that you first compile the class mentioned in the error message and see if this solves the problem. Then you should schedule for a new full compile of the application.

Friday, June 7, 2013

AX World End Date

In some cases you will need to use the highest date available in a datetime field in Dynamics AX 2012.
Microsoft has decided that this date is:

December 31, 2154

Specifically when handling Date Effective Data in AX 2012, you might encounter date fields with the value "Never" when viewing it in the table browser. The field actually contains the date Dec 31, 2154.

When writing, updating or querying date effective records in x++, you can use the date 31\12\2154.
But a more accurate and less cryptic apporach would be to use the maxDate system function:

myDateEffectiveRecord.ValidTo = maxDate();


Friday, October 26, 2012

Get rid of "The model store has been modified" dialog

After upgrading Microsoft Dynamics AX 2012 you will get the following dialog upon starting the AX client:

When you have performed the appropriate upgrade actions (AOT compile, code check, CIL compile, synchronize, upgrade scripts), the dialog still might pop up every time you start the client. Selecting "Skip" will not solve this.

To avoid the dialog from appearing, you can do one of the following:

  1. If you have started one of the checklists, check that you have marked alle the actions as complete by clicking the link "Mark as complete" on each action.
  2. Prevent the dialog from appearing by clicking
    System administration > Setup > Checklists > Prevent startup of checklists

I would prefer the first alternative, since it will require you to confirm that you actually performed all the necessary upgrade steps.

Wednesday, October 17, 2012

Simple page number field in AX 2012 SSRS report

When developing AX 2012 reports in Visual Studio you might want to add a simple page counter field that shows both the current page number and the total number of pages and is prepared for any language.

Looking at the SalesInvoice report, the page numbering is done using four fields:

Copying this to another report/layout will require some adjusting, since the information is split up into four fields. Also, if you are (for some reason) printing thousands of pages, you might need to adjust the field widths.

To add a simple page numbering field to your report, create a new placeholder in a field and set the value expression to:

=Labels!@SYS7426 + " " + CStr(Globals!PageNumber) + " " + Labels!@SYS70751 + " " + CStr(Globals!TotalPages)

This will produce an output like this: