Posts

Check if feature is enabled

Image
 Features can be difficult to check if is enabled. Some have helper classes, some do not, some are even final and private, so how do you check if a feature is on. Just by coincidence we got a custom hotfix, only code, related to a performance issue with Retail. In that code we got a way to check features.  private boolean shouldUseRetailPricingDataManagerV3()     {         RetailPricingSharedParameters parameters = RetailPricingSharedParameters::find();         FeatureManagementState state;         FeatureManagementMetadata featureData;         select firstonly IsEnabled, RecId from state             join featureData             where state.RecId == featureData.FeatureState             && state.Name == 'Dynamics.AX.Application. Retail Discount PerformanceImprovementFeature   ';         return (state.RecId == 0 ||state.IsEnabled == NoYes::Yes)             && !Global::isFlightEnabled(' RetailPricingStopFlattenDiscountFeatures  ')             && !pa

Joining 1:N related table in form without row duplication using Computed fields in views

Image
Case A customer wanted to display and filter Customer reference and Customer requisition fields from sales order on Project invoice journal screen. As there is no direct link to do this and the indirect link is a 1:N or even N:N in certain cases this gets problematic when displaying the journals. Resulting in duplicate journal entries in the journal overview. As the customer only have one sales order pr. project invoice  and we are selecting the first only (Top 1) this will not be an issue. As joining and display methods do not provide filter and sort options we need to generate the data on the server using computed fields. Explanation As display methods do not provide filter and sort options and joining 1:N table relations will duplicate the journals in the list, we need to generate the data on server using computed fields. To do this we need a View with Proposal ID, join the view to the ProjInvoiceJour table on Proposal ID and add the view as a datasource to the form ProjProposalJour

Data Entity add computed field

Image
 We have this product import module that has a lot of entities, the main identifier or product number is store in one table. The references to that product is through a GUID. In one of the entitties I need to add a computed field for export. The fastest way to do this is to add a computed string value. One could think that adding some postLoad logic would do the trick, but this field will then not be exported through Data management, only visible in OData. I've added these two fields: EPDNr is not a computed field but populated in the postLoad method with this syntax: public void postLoad() {      EPDProduktDto produktDto;           super(); select firstonly EPDNr        from produktDto           where produktDto.ProduktGUID == this.ProduktGUID;           this.EPDNr = produktDto.EPDNr; } EPDNrComputedField is as you might have guessed a computed field. Populated on the server with the method below, please do notice that the values are not in quotations, looks like server a

SysOperationFramework with use of Query

Image
 The SysOperation framework is very good and effective, but unforutnatly a bit complicated to get in to and do as you want.  I had one case in which a simple table should be updated, the job was to be able to set in batch. Also it had to use a query so that the user could easily set up the ranges as he pleased. Note that I will use the same query for updating the table which I mentioned. So the same query is used all the way through ending in using Quer::updateRecordset For this you need: Data contract class Controller class Service class Simple query oject Action Menu item Main menu where to make the menu item available. 1. Data contract class Note the simple query highlighted in bright yellow .  [DataContractAttribute     , SysOperationGroupAttribute('Parameters',  "Parameters", '1')] internal final class CustAutoCancelUpdateDataContract {     str             packedQuery;     MCRAutoCancel   autoCancel;     public Query getQuery()     {         return new Qu

Financial dimensions display on form

Image
Financial dimensions is a complex topic since AX 2012, same in D365FO. They can vary for every installation done.  Lately I got a request to display the financial values and that they should also be available to use as filters. I started the task and tried to use the "Add financial dimensions for ODATA" addin. But for some reason I could not make it work and consistently get the error:  The form datasource: 'DimensionSetEntity' is bound to an unsupported entity type As an alternative I did it the old fashioned way, by the means of a view and some code in a helper class.  You will need a helper class which fetches your dimension attributes individually, these will be hard coded as they will not change. Helper class View with methods Add methods as computed fields to view Add view to form Override form datasource Process 1. Create a helper class Name: FinancialDimensionHelper_[YourPostfix] Methods: one for each financial dimension: Code:  private boolean shouldUseRetail

Open in Excel with filter

Image
 I've found that the open in Excel functionality was lacking in certain aspects. Technically for forms not implementing the office add-in excel interface they retrieve data with only possible filters being company filter and current record filter. A customer of ours wanted to open Project item requirements already filtered with lookup on specific columns. As it is not possible to implement interfaces on form extensions, so another solution was needed.  Requirements: - Open in excel data pre-filtered on project id Pros: - Programmatically control filters and columns Cons: - Does not use Office templates In this example I will be using the entity ProjSalesItemRequirementEntity .  Prepare your entity It is basic out of the box without anything in the  AutoReport  field group.  First task is to add all key filds and wanted columns. The key fields enables you to publish back to D365, without them you cannot publish.  The key fields are DataAreaId and ProjectTransactionId, the other fiel

Data Management handle project finished running

Image
If you only want to know how to determine if a project has finished running go to Step 2: determine  when a project has finished executing. In a Data Management project there might be several entities in which data is to be inserted. Knowing when all these entities have finished executed is not straight forward. A customer wanted to post a journal automatically that was created by a Data Management project. In this example I will explain how to mark a journal for posting and posting the journal created [via Data Management] after the project has finished executed. Step 1: mark the journal for posting Create a table to store which journals to post, RefrecId or JournalId, whatever is best in your case.  In my case it looked like this: Of the entity in which your journal is inserted, create a data event handler on inserted event type    [DataEventHandler(tableStr(PDIJournalTableEntity), DataEventType::Inserted)]     public static void PDIJournalTableEntity_onInserted(Common sender, DataEv