Sunday, July 25, 2021

Table extensions in D365FO

 Source: Customize through extension and overlayering - Finance & Operations | Dynamics 365 | Microsoft Docs

You can create a table extension to extend a table's design and logic. You can add new fields, field groups, indexes, mappings and relations. You can also add new fields to existing field groups, change the label of a table field, change the Created By, Created Date Time, Modified By, Modified Date Time properties. Using table extensions, you can also change the Extended Data Type property on fields and set it to an EDT that is derived from the current EDT (This is available as of platform update 8).

In Microsoft Dynamics AX 2012, you could override the virtual methods of a table's base class to control the behavior that occurred during table operations, such as when creating, reading, updating, or deleting. In the current version, you instead use extensions to implement event handlers that are called from the base implementations of the table methods. The following table lists each table method and its events.

TABLE EXTENSIONS
Published Table methodPreceding eventSucceeding event
validateWriteValidatingWriteValidatedWrite
validateDeleteValidatingDeleteValidatedDelete
validateFieldValidatingFieldValidatedField
validateFieldValueValidatingFieldValueValidatedFieldValue
modifiedFieldModifyingFieldModifiedField
modifiedFieldValueModifyingFieldValueModifiedFieldValue
InsertInsertingInserted
UpdateUpdatingUpdated
DeleteDeletingDeleted
InitvalueInitializingRecordInitializedRecord
FinalDeleteValidationExecuted when a delete operation is performed on a table object, before the operation is committed to the underlying database tableN/A
FinalInsertValidationExecuted when an insert operation is performed on a table object, before the operation is committed to the underlying database tableN/A
FinalReadValidationExecuted when a read operation is performed on a table object.N/A
FinalUpdateValidationExecuted when an update operation is performed on a table object, before the operation is committed to the underlying database table.N/A

Validation events capture and return results by using the DataEventArgs parameter. The display and edit method modifiers are supported on table extensions.

Form extensions in D365FO

Source:  Customize through extension and overlayering - Finance & Operations | Dynamics 365 | Microsoft Docs

You can extend the functionality of a form by extending its controls and data sources. For example, in a form extension, you can:

  • Add a new control.
  • Enable or disable a control.
  • Change the text or label property of a control.
  • Change a control's visibility.
  • Change a form's help text.
  • Change a form's caption.
  • Add a new data source.
  • Add a form part.

Other ways to customize a form, such as reordering controls in the form are planned to be included in a future release. In Microsoft Dynamics AX 2012, you could override form methods. In the current version, you use extensions to implement event handlers that are called from the base implementations of form methods. The following table lists each method and its associated events.

FORM EXTENSIONS
Published form DataSource methodPreceding eventSucceeding event
activeN/AActivated
deleteDeletingDeleted
validateWriteValidatingWritingValidatedWrite
writeWritingWritten
createCreatingCreated
executeQueryN/AQueryExecuted
linkActiveN/APostLinkActive
initN/AInitialized
validateDeleteValidatingDeleteValidatedDelete
rereadN/AReread
selectionChangedN/ASelectionChanged
markChangedN/AMarkChanged
leaveRecordLeavingRecordLeftRecord
FORM EXTENSIONS
Published form Object methodPreceding eventSucceeding event
initInitializingInitialized
closeClosingN/A
runN/APostRun
activateN/AActivated
TABLE 3
Published form Control methodPreceding eventSucceeding event
modifiedN/AModified
validateValidatingValidated
leaveLeavingLostFocus
enterN/AEnter
gotFocusN/AGotFocus
clickedN/AClicked
selectionChangeSelectionChangingN/A
pageActivatedN/APageActivated
allowPageDeactivateAllowPageDeactivateN/A
expandExpandingExpanded
tabChangedN/ATabChanged
dialogClosedN/ADialogClosed

Monday, July 19, 2021

Create Deep links in D365FO

The URL Generator must be used from code running on the AOS, in an active user session or batch process. This requirement ensures that the URL can be secured through encryption specific to the instance that generates the URL. At a minimum, the following information must be specified and passed to the URL Generator in order to generate a working URL.

  • Host URL
    • The URL of the web root for the instance. For example: https://ax.dynamics.contoso.com/
  • AOT name of the Menu Item Display
    • The menu item display to be used to open the form.
  • Partition
    • The partition to use for the request.
  • Company
    • The company to use for the request.

 



// gets the generator instance

var generator     = new Microsoft.Dynamics.AX.Framework.Utilities.UrlHelper.UrlGenerator();

var currentHost   = new System.Uri(UrlUtility::getUrl());

generator.HostUrl = currentHost.GetLeftPart(System.UriPartial::Authority);

generator.Company = curext();

generator.MenuItemName = <menu item name>;

generator.Partition = getCurrentPartition(); 


// repeat this segment for each datasource to filter

var requestQueryParameterCollection = generator.RequestQueryParameterCollection;

requestQueryParameterCollection.AddRequestQueryParameter(

    <datasource name>,

    <field1>, <value1>,

    <field2>, <value2>,

    <field3>, <value3>,

    <field4>, <value4>,

    <field5>, <value5>

);


System.Uri fullURI = generator.GenerateFullUrl();


// to get the encoded URI, use the following code

fullURI.AbsoluteUri


Source: Create shareable, secured URLs (deep links) - Finance & Operations | Dynamics 365 | Microsoft Docs

Monday, July 5, 2021

dimensionDefaultingController::findBackingEntityInstance(); in D365FO

 DimensionAttributeValue dimAttrValue =

    DimensionAttributeValue::

        findByDimensionAttributeAndValueNoError(

            dimensionAttributeTable, dimensionValue);

if (dimAttrValue) {

    common = dimAttrValue.getEntityInstance();

}


Example:


dimAttrValue            = DimensionAttributeValue::find(dimAttrValueSetItem.DimensionAttributeValue);

                dimAttr                 = DimensionAttribute::find(dimAttrValue.DimensionAttribute);

             //   dimensionValueEntity    = DimensionDefaultingControllerBase::findBackingEntityInstance(curext(),dimAttr,dimAttrValue.EntityInstance);

                DimensionAttributeValue dimAttrValue = DimensionAttributeValue::

                                                            findByDimensionAttributeAndValueNoError(

                                                                dimAttr, dimAttrValue);

                                                                    if (dimAttrValue)

                                                                    {

                                                                        dimensionValueEntity = dimAttrValue.getEntityInstance();

                                                                    }

                dimensionValue          = dimAttrValue.getValue();

Workflow last comment

  display public server  WorkflowComment  workflowLastComment()

    {

        WorkflowTrackingTable           workflowTrackingTable;

        WorkflowTrackingStatusTable     workflowTrackingStatusTable;

        WorkflowTrackingCommentTable    workflowTrackingCommentTable;


        select firstonly ContextCompanyId, ContextTableId, ContextRecId from workflowTrackingStatusTable

            where workflowTrackingStatusTable.ContextCompanyId    == curext()

               && workflowTrackingStatusTable.ContextTableId      == this.TableId

               && workflowTrackingStatusTable.ContextRecId        == this.RecId

            join firstonly TrackingId, CreatedDateTime from workflowTrackingTable order by CreatedDateTime desc

                where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId

            join Comment from workflowTrackingCommentTable

                where workflowTrackingCommentTable.WorkflowTrackingTable == workflowTrackingTable.RecId;


        return workflowTrackingCommentTable.Comment;

    }