Save a Predefined Query to Use for All the Users

If you have a business requirement that requires saving the filtered query to use it later for all the users (whenever the user opens some form, this form will be opened as it is on the predefined query)– that means that you would need to make new development.

 

My requirement was the following: For all users whenever they open this form “All project quotation” from “All Customers” the form should be opened as It is on the predefined query, and they wanted to be able to change this query when is needed.

 

Step-by-step Instructions for Dynamics 365

 

1. The first step is to create a new table where you can save a filtered query. The field should be a type of container to save the query run. I made the logic for this table in such a way that there will always have only one record.

 

 

2. Then we should create a new service class, controller, and contract to save the query.

 

For my requirement, I needed to save the SalesQuotationListPage_Proj query which is set on the property on the MenuItemDisplay – the menu item for the “All Project Quotation” form.

 

 

 

 

 

3. We need to create a new action menu item set the controller class on it, and to place this menu item somewhere in AX client so the user will be able to set this query as he wants.

 

4. After saving this query on the table now we should change the query on the original form with the saved one. For this purpose, I made the extension on the CustTable form (because my requirement was this form to be opened by All customers). I added a new Command button and copy the event handler Clicked to write the logic.

 

 

5. I created a new display menu item for the “All Project quotation” form and set the Form View Option to GRID. I made this because whenever I opened the form the detailed view was opened, this change helps me to solve that problem.

 

 

6. I Wrote a new event handler class and paste the event handler for the clicked method. You need to include the args.initialQuery()to set the saved query.

 

 

Note: Also there is another way to change the query on the existing form, you can use Chain Of Command. New extension class for the “All project quotation ” from and put this code args.initialQuery(query) in the Init() method before next().

Generate a New Voucher Number for Each Inventory Journal Line

If you have a business requirement that requires a new voucher number to be generated for each posted inventory movement journal line – that means that you would need to make customization to the out-of-the-box functionality for generating vouchers for inventory journals.

 

Out of the box functionality that we have so far is that a new voucher is being generated on:

 

  • Change date: For each different date in the inventory journal lines.

 

    • Example: If we have an inventory movement journal with 10 lines, 4 lines with date 1/10/2020, and 6 lines with date 4/10/2020, this setup would post the journal and generate 2 voucher numbers: 1 voucher number for the lines with the date 1/10/2020 and 1 voucher number for the lines with the date 4/10/2020.

 

  • Change date or item: For each different date or item in the inventory journal lines.

 

    • Example: If we have an inventory movement journal with 10 lines, 4 lines with item itemnumber1 and 6 lines with item itemnumber2 and all lines having the same date, then this setup would post the journal and generate 2 voucher numbers: 1 voucher number for the lines with the item itemnumber1 and 1 voucher number for the lines with the item itemnumber2.

 

This is defined in the setup of the inventory journal name:

 

AX2012: (Inventory management/Setup/Journals/Journal names, inventory/General/Voucher)
D365: (Inventory management/Setup/Journal names/Inventory/General/Voucher)

 

 

 

So, this blog post is about how to extend this functionality by enabling the generation of a new voucher per journal line.

 

Example: We have 10 lines in the inventory movement journal, and we want to generate 10 different vouchers -one voucher per journal line.

 

Step-by-step Instructions for AX2012

 

  • The first step is to extend the enum InventJournalVoucherChange and add a new option ‘Line change’:

 

 

    • After this step, we should be able to select ‘Line change’ as an option in the inventory journal name setup:

 

 

  • Then we should modify the class InventJournalTransData and override the initVoucher method. This method is the place where we can control the voucher number generation for each journal line.

 

 

  • Now, we want to keep the same logic for voucher numbers when the setup is ‘Change date’ or ‘Change date or item’.

 

    • For that purpose, we need to copy the code from the \Classes\JournalTransData\initVoucher and add it in case the setup is ‘Change date’ or ‘Change date or item’. In case the setup is our new option ‘Line change’, then we need to add a code that will generate the new voucher number.

 

    • After these changes the initVoucher method on the InventJournalTransData should look something like below:

 

 

  • Now, when we create an inventory movement journal with 10 lines and post the journal, we will see 10 different vouchers created for each journal line.

 

Step-by-step Instructions for D365

 

  • The first step is to create an extension of the enum InventJournalVoucherChange and add a new option ‘Line change’:

 

    • After this step, we should be able to select ‘Line change’ as an option in the inventory journal name setup:

 

 

  • Then we should create an extension of the class InventJournalTransData and using Chain of command we will add the new initVoucher method.

 

    • Please note that this solution needs to call the super() (next call) and for that reason is going to create a new voucher number in the super call, and then we are going to override that voucher number with a new one.

 

  • Now, when we create an inventory movement journal with 10 lines and post the journal, we will see 10 different vouchers created for each journal line.