Category: Plugin

Create log in Plug-in using Custom Entity

Create log in Plug-in using Custom Entity

Sometime we want to know what is going on in our plugin code. When the plugin code is very large then we need to write the code for every step which is executed successfully or not.

For Debugging a Plugin we can –

  • Use ITracingService
  • Attach Plugin Registration Tool with VS and debug it.

For more info please refer the below links.

To review more options for external logging, you can also go through the below link.

Author by Salim Adamon

Error Logging Options in CRM

https://community.dynamics.com/crm/b/salimadamondynamicscrm/archive/2013/08/14/error-logging-options-in-crm

In this Blog, we’ll talk about creating log in plug-in using custom entity.

Let’s create an entity i.e. am_log in our CRM.

1

and create attributes which are required for this entity like

am_status ,  am_errordescription.

2

As we all know that creating a record in CRM is very easy but If you are writing logs in a failing transaction of Plugin, then the entire transaction will be rolled back including creation of logging records.

To avoid this roll back of logging records we can use ExecuteMultipleRequest.

For more info about ExecuteMultipleRequest refer to below link

https://msdn.microsoft.com/en-in/library/jj863631.aspx

In this process first we create a plugin, here named as LoggingUsingCustomEntity.

First we need to Create object for ExcuteMultipleRequest and assign settings that define execution behavior  i.e.

ContinueOnError =false,

ReturnResponse=true

ex

exmultiple

Lets say before creating a new account we need to count all Accounts(or any other business requirement) that already present in CRM that create success log in our Log Entity.

success

Now we write invalid expression for creating new account that generate error log in our Log entity.error

According above code log records will create two times,  one for getting all accounts successfully and other for error that is Account doesn’t contain “Name” attribute.

Let’s we deployed this plugin code on Account Create Message and see what will be generates in Log entity.

last.PNG

It created successfully what we expected 🙂

It won’t be created and also roll backed if we use normal create request here.

here is the link of  Plugin complete code.

http://1drv.ms/1MZBBzi

 

Thanks for visiting my blog.

Do some creative stuff in CRM  !!!  🙂

 

 

 

MS CRM dynamics with Firebase(using c#)

MS CRM dynamics with Firebase(using c#)

In my previous blog I wrote about how we can use firebase with CRM Dynamics in client side.
Here is the link MS CRM dynamics with Firebase (Using JS)

Today I am going to explain, how we can use Firebase with Plugin or Custom workflow in CRM using C#.

Let’s create a class library and add a class FirebaseWithCRM.cs

For communicate from CRM plugin to Firebase, we use FireSharp. It is a .net library for Firebase Rest Api.

c1

Next we add CRM core assemblies in our Class library project.

c2

We register this plugin on pre-operation event of Account Entity and on create Message ,so whenever new Account is create it ‘ll modify/add Account data in Firebase.

c3

Add new file as FirebaseHelper.cs that contain Push function

c4

c5

But our code is depends on some other DLL like Firesharp, Newtonsoft.Json , System.Net.Http , Microsoft.Threading.Task etc.

So Need to Merge all Dll’s into single one.

c6

What is ILMerge ?

ILMerge is a utility for merging multiple .NET assemblies into a single .NET assembly. It works on executables and DLLs alike and comes with several options for controlling the processing and format of the output.

For info refer this link

http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx

 

For Merging Dll’s there is a Nuget Package MSBuild.ILMerge.Task so using this package we can merge all DLL’s.

You can also refer this article for more understanding about DLL’s Merge by Nicolas Niwonski.

 

c7

 

c8

After Merging we can deployed this DLL using Plugin Registration tool on pre-operation event for Account Entity and on Create Message.

You can also register on Post-operation event by this we get Guid of account entity and store it in Firebase.

c11.PNG

That’s it Now we can test. 🙂

c9

C10

Now when we create New account it created in Firebase under Accounts Node.

For more synchronous and asynchronous function for Firesharp, please refer below link

https://github.com/ziyasal/FireSharp/wiki/v1-Docs

 

 

Thanks for visiting my blog.

Do some creative stuff in CRM  !!!  🙂