Showing posts with label Dynamics 365/AX7. Show all posts
Showing posts with label Dynamics 365/AX7. Show all posts

September 23, 2018

RecordInserList class for optimized insert operation


Hi Folks,

RecordInsertList class is the really useful and fastest way to insert records in AX table(s). This method is useful you don't want to run any validation while insertion for an example; insert in a temp table or SSRS reports. 

Below is the simplest example of set based RecordInserList class,
void copyVendor()
{
    VendTable    sourceVend;
    MyTmpTable   targetVend;

    //RecordInserList calss decarion
    RecordInsertList VendList;

  //Object initialization
    VendList = new RecordInsertList(tableNum(Vendtable));

    while select sourceVend
    where sourceVend.vendgroupId == ‘Local’
    {
        targetVend.data(sourceVend);
        targetVend.vendorAccount = sourceVend.vendorAccount;
           .
           .
           .
           .
        VendList.add(targetVend);
    }
    VendList.insertDatabase(); //mandatory call
}


Another example from MSDN

public void tutorialRecordInsertList()
    {
        MyTable myTable;
        RecordInsertList insertList = new RecordInsertList(
            myTable.TableId,
            True);
        int i;
      
        for ( i = 1; i <=  100; i++ )
        {
            myTable.value = i;
            insertList.add(myTable);
        }
        insertList.insertDatabase();
    }

RecordInserList class will capture all record in temp and hit The DataBase only once when we call insertDatabase(). add() insert certain blocks followed by insertDatabase to complete the insert operation. 
This is how we can reduce the SQL call and optimize the performance as well.

Cheers,
Harry

Follow us on Facebook to keep in rhythm with us. @Facebook


August 12, 2018

Edit/Display or new methods on standard application objects

Hi Folks,
Let’s see how to write a new method on standard application object using the extension framework. An extension enables you to add functionality to existing model elements and source code.
Before starting adding new method, you need to create a new extension class for your object and this class should be declared as final and post fixed by ‘Extension’ keyword. See below example,

For Table:
[ExtensionOf(tableStr(CustTable))]
final class MyCustTable_Extension
{
<new methods>
}

For Class:
[ExtensionOf(classStr(CustExchAdj))]
final class MyCustExchAdj_Extension
{
<new methods>
}

For Form:
[ExtensionOf(formStr(VendParameters))]
final class MyVendParameters _Extension
{
<new methods>
}

Now lets see how to add different types of methods

1. New edit method
For Extension methods, the first argument in method parameter must be the object you're extending e.g. table buffer. See below code for reference;
public static edit str60 MyFieldEdit(<tableName> _this, boolean _set, name value)
{
MyTable mytable = <tablename>;
if(_set)
{
if(value)
{
ttsbegin;
custTable = CustTable::find(<tablename>.CustAccount,true);
custTable.Name = value;
custTable.update();
ttscommit;
}
}
}

2. New display method
public static display EcoResDescription productName(InventSum _this)
{
Return _this.itemName();
}

3. Normal method
In the same way, you can write a new method, this method also needs to be static so it can be accessed on the form.
Public static updateSearchName(_this, Name _newName)
{
Mytable mytable = _this;
If(_newname)
{
Ttsbegin;
Mytable.searchName = _ newname;
MyTable.update();
Ttscommit;
}
}

Edit method on table extension or new methods on table extension, all method needs to be static. Now to access these methods, go to your form and add new field type of string/real/XYZ. Set below property
clip_image002

Cheers,
Harry

July 14, 2018

Solution: Best practice (BP) warning suppression in Dynamics 365 FO

Hi Folks,

In this post, we will discuss how to suppression the best practice warnings while development. It's always recommended to remove/fix all best practice warnings before check-in your code to VSTS. To see all the BP warnings on your project; right click on the project and select Run Best practice Fixer on <Project name>
image

This step will show all the BP warnings for the selected project. Let's see what all the ways we have to fix these.

1. In code itself:
Add suppression line before your method,  with warning type and justification, the syntax is below
[SuppressBPWarning(‘<BPWarningType>’, <Description/Justification>.)] for example [SuppressBPWarning(‘BPParameterNotUsed’, Parameter required by the event interface.)].

This is an example for the same.

clip_image002

2. Edit Best Practice Suppression file (AxIgnoreDiagnosticList)
Every model should have a BP suppression file named AxIgnoreDiagnosticList, for system models, you can find related BP suppression file at
K:\AosService\PackagesLocalDirectory\<ModelName>\<ModelName>\AxIgnoreDiagnosticList

Right-click on your project and select ‘Edit Best practice Suppression’. For all system models, this action will open the related BP suppression file.
clip_image004

For a new model:
In case you created a new model for your development (of course you would Smile )  you have to create this file manually the first time, and on a later stage, you can amend for all BP fixes.
Create a new XML file under below path, I recommend to use a separate Visual studio instance for Create OR Edit this file.

K:\AosService\PackagesLocalDirectory\<yourModel>\<YourModel>\AxIgnoreDiagnosticList

Copy paste below

<?xml version="1.0" encoding="utf-8"?>
<IgnoreDiagnostics>
<Name>myModel_BPSuppressions</Name>
<Items>
<Diagnostic>
<DiagnosticType>BestPractices</DiagnosticType>
<Severity>Warning</Severity>
<Path>dynamics://<warning path></Path> //You can get this path from warning message
<Moniker>BPParameterNotUsed</Moniker> //You can get this from error message
<Justification>FormDataSourceEventArgs e is mandatory parameter for events and not used in the current context.</Justification>
</Diagnostic>
</Items>
</IgnoreDiagnostics>

Keep adding below tag for every warning

<Diagnostic>
<DiagnosticType>BestPractices</DiagnosticType>
<Severity>Warning</Severity>
<Path>dynamics://<warning path></Path> //You can get this path from warning message
<Moniker>BPParameterNotUsed</Moniker> //You can get this from error message
<Justification>FormDataSourceEventArgs e is mandatory parameter for events and not used in the current context.</Justification>
</Diagnostic>
</Items>
</IgnoreDiagnostics>

Some recommendations:
1. Best would be to create a new file using VS and place in the respective folder. Also, while adding new records best would be to edit this file from separate VS instance rather than same solution explorer.
2. You will find the BPWarningType in the warning message. If you not sure about the justification OR if you want to make consistency with system existing BP suppression, see the standard code.
3. I recommend using a separate Visual studio instance for Create OR Edit this file.

Cheers
Harry…

November 23, 2017

How to Delete a model in Dynamics 365 for FO


I was trying for this for very long time, on initial stage of development it was one of the biggest headache for me. HOW TO DELTE A MODEL. So now finally I come to conclusion on this.

Note: I would recommend check with all other developer who is sharing the same dev machine before deleting this to make nothing will go wrong. Take a backup of your code.

Prerequisite:
1.     Login to server using admin credentials
2.     Check your model directory it must be sore under below path/folder
C:\AOSService\PackagesLocalDirectory/<your model>





There can be two scenarios here,
1.     Model belongs to its own package
2.     Model belongs to standard (existing) package.

1.     If your model belongs to its own package (For example: An extension package with no other models in the package):
a.      Stop the following services: The AOS web service and the Batch Management Service
b.     Delete the package folder C:\AOSService\PackagesLocalDirectory\<your model>
c.      Restart the services from step 1
d.     If Visual Studio is running, refresh your models (Visual Studio > Dynamics 365 > Model management > Refresh models)
e.      In Visual Studio, perform a full database synchronization (Visual Studio > Dynamics 365 > Synchronize database...)





2.     If your model belongs to a package with multiple models (For example, <your model> overlays Application Suite):
a.      Stop the following services: The AOS web service and the Batch Management Service
b.     Delete the model folder C:\AOSService\PackagesLocalDirectory<PackageName>\<your model> (In this example PackageName=ApplicationSuite)
c.      Restart the services from step 1
d.     In Visual Studio, refresh your models (Visual Studio > Dynamics 365 > Model management > Refresh models)
e.      In Visual Studio, build the package that the deleted models belonged to (Visual Studio > Dynamics 365 > Build models...)
f.       In Visual Studio, perform a full database synchronization (Visual Studio > Dynamics 365 > Synchronize database...)


Enjoy..
Harry.

Disc: This post is referred from here.


November 11, 2017

Mobile app development in D365 for FO - Part I

Hi Folks,


This is my first post on mobile development, here I am going to share basic development steps (that’s doesn’t require any coding really.) J MS released a new mobile app for Android and iOS named as “Microsoft Dynamics 365 Unified Operations”, MS keep releasing new exciting feature and support in a timely manner.

1.      Download Microsoft Dynamics 365 Unified Operation app from your mobile store



2.      For the first time, you need to use your D365 application URL and valid credentials to open this app



3.      Now go to your web browser and open D365. On the right top corner select setting > Mobile App






4.      Your browser will split into two portions, left one for D365 web browser while right side for mobile application configuration, like below


 
5.      For this demo, let’s take an example of Customers. Click on create button


6.      We will add a new mobile workspace for Customers and a page for “All customer”


7.      You will be navigated to the next screen for “All customer”, where you need to select fields for this App page. Go to Accounts receivable > All customers and click on “Select fields” in all customer page.





8.      When you click on “Select fields” on AX side “All Customer” form few fields will be highlighted, shown in below image

















9. Click on “+” sign next to each field to add them to your mobile app page. As you select these fields they will appear in right side window where you are configuring your mobile app. Once you select all your required fields click on Done.



10. On the next screen, to set any further property click on the Property button which is available for each selected field.


11. Now click on Back > Done > Save.
12. As a final step, you need to publish this app workspace, select your workspace and click on Publish button on top.


13. You get a system notification on the successful action.


14. I have tested this on an android device, go to your app. I hope you already logged in successfully in the mobile app earlier. Now pull down the screen to refresh ( as we do in most of the mobile app like Facebook, LinkedIn, Outlook). A new workspace must appear in the app, Customers, below are the screenshots from the app.


 






Here the sequence of a field that you selected during field selection for a page is very important, we choose Customer group first than Customer account hence we got Customer group on top of each record. So, choose your fields carefully.

In the next post, we will discuss how to create a new record using the mobile app. We will be continuing the same app there.

Enjoy…!!!

Thanks
Harry

July 13, 2017

Important links for Dynamics 365

image
Hi Folks,

Here are some important links that you check for your routine work, update, RnD, submit a suggestion and many more. 


Enjoy….
Harry
PS: Photo taken from MS site.

May 19, 2017

Breakpoint not hit in Visual studio [Dynamics 365]

Hi Folks,





Situation: While put a breakpoint and try to hit debug on any object which is not a part of your solution/project; Breakpoint will not hit. You will get below message.

“The breakpoint will not currently be hit. No symbols have been loaded for this document.”

clip_image001[8]

Possible reason: This is because of one of Debugger property that will not load any symbols for other than Solution/Project objects.
 
Solution: To enable such debugging, you have to set the debugger property,
Uncheck this option Load symbols only for items in the solution as shown below snaps,

Step 1: Go to Dynamics 365 menu in Visual studio and select option

clip_image002[7]

  
Step 2: Choose Debugging option from list and uncheck the Load symbols only for items in the solution

clip_image003

Now try to run again, this time breakpoint should hit as expected.

Enjoy…!!!

Harry 

May 13, 2017

Send Message to all Online users [Dynamics 365 FO]

Hi Guys,

In D365 where we manage most of the things using LCS, if there is any Planned/Unplanned activity need to perform on server and down time require.
In such case, you need to send a message to all online used for that particular environment. To do that simply follow below steps,

Step 1: Login into your LCS account. 

Step 2: Under Environment section > select your environment. > Click on maintain option > Select Message online users.

clip_image001[4]

Step 3: Here you will have two options
i.                    Broadcast a new message for downtime: Post a new message
ii.                 Cancel message: To cancel any previous posted message.

clip_image003[4]

Step 4: Select Broadcast a new message for downtime, you have to provide message start date time and when this operation will begin OR massage valid to date time. click on Post button and click when asking for confirmation.

clip_image004[4]

Step 5: When a user will login into environment he/she must get this message
clip_image005[4]

Step 6: Now if in case you have to postpone or cancel this activity, choose second option i.e. Cancel message, system will ask which message you want to cancel as there can be multiple messages.
clip_image006[4]

Let’s try to cancel first message that we created in last step. In the right corner, you will found a delete icon, click on that icon and hit yes when ask for confirmation. You will see now only two messages are active here

clip_image007[4]

Now when user will login in next time he/she will not any notification from system.

Enjoy…
-Harry.

May 06, 2017

Merger two LedgerDimension in Dynamics 365

Hi Folks,

In my previous post I shared  information about new classed that introduced in D365 for Dimension actions. In this post, I am sharing a sample code to merge two different ledger dimension and get a new LedgerDimension id.
This is rough code, please feel free to copy and update it according to your requirement.

public static void main(Args _args)
   {    
       LedgerJournalTrans  ledgerJournalTrans1, ledgerJournalTrans2 ;
       RefRecId            dim1, dim2, mergerDim;
      
  
       select firstonly TrvExpTrans where TrvExpTrans.ExpNumber == "USMF-000565";
       select firstonly AccountingDistribution where AccountingDistribution.SourceDocumentLine == SourceDocumentLine::find(TrvExpTrans.SourceDocumentLine).RecId;
       //AccountingDistribution::
       dim1 = TrvCostType::find("mycategory").LedgerDimension; //First dimension
       dim2 = 5637236123;//AccountingDistribution.LedgerDimension; //Second dimension
       mergerDim = LedgerDimensionFacade::serviceMergeLedgerDimensions(dim1, dim2);
     
      info(strFmt("Dim1: %1" , DimensionAttributeValueCombination::find(dim1).DisplayValue));
      info(strFmt("Dim2: %1" , DimensionAttributeValueCombination::find(dim2).DisplayValue));
      info(strFmt("merge dim: %1", DimensionAttributeValueCombination::find(mergerDim).DisplayValue));
  
   }

Please share your queries/feedback in comment box, I will be happy to help you.

-Harry