CRM 2011 – How to get the current user from within a worflow

CRM 2011 – How to get the current user from within a worflow

Today I needed to get the Current User inside a workflow activity. In CRM 2001 process it is not possible to get current user and in some cases a reference can be necessary in order to set the right user.
A Custom Workflow Activity can be created for this purpose, taking advantage of the InitiatingUserId property.

public class GetCurrentUser : CodeActivity
        [Output("Current User")]
        public OutArgument<EntityReference> CurrentUser { get; set; }
        protected override void Execute(CodeActivityContext context)
            IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext>();
            CurrentUser.Set(context, new EntityReference("systemuser", workflowContext.InitiatingUserId));


Now from our workflow activity we have the current user.

CRM2011 – Search what is the database associated at Organization

Sometimes I need to search what is a database associated at an existing organization. It is simple: From CRM Server, we need to ope SQL Server tools and execuete this query:

By running this query within MSCRM_CONFIG database we should be able to easily identify each organization:

SELECT [DatabaseName]
FROM [MSCRM_CONFIG].[dbo].[Organization]

That’s all…

Merging .NET assemblies using ILMerge

Today I had a problem about multiple dll registration plugin for MSCRM. This plugin was registered on Database and I could not update this one because I needed the others libraries. I had two soltions: First, I could register it on GAC. I don’t like because I had problem on production during the installation of the new solution. The second one was to use ILMERGE to merge all dll and create an unique dll to register. I choose the second solution. ILMerge is useful tool on Microsoft. This little gem makes it possible to link multiple assemblies to a single one.

First, you would compile your libraries to DLLs and your program to an EXE referencing the DLLs. This is exactly what Visual Studio would do if you had multiple libraries and a program referencing these libraries, so there is no need to do this on the command line.

Later you can link these parts to a single self-contained EXE, DLL, using ILMerge:

echo %1
%1Build\ILMerge.exe /keyfile:%1Properties\keys.snk /target:library /copyattrs /targetplatform:v4,"C:\Windows\Microsoft.NET\Framework\v4.0.30319" /out:%1Build\final\namedll %1Build\library.dll %1Build\Castle.Core.dll %1Build\Castle.Windsor.dll %1Build\Microsoft.WITDataStore.dll %1Build\Newtonsoft.Json.dll %1Build\Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll

The nice thing about this is that you can also merge third party assemblies like commercial class libraries into your program. And you do not have to modify your build process.

I found ILMerge tremendously useful, and I think that something like this should be a part of the .NET framework SDK. Maybe just enhance al.exe so that it can also link DLLs.

I have only scratched the surface of the .NET build process and the capabilities of ILMerge, and this article might contain many inaccuracies or even errors. But I found ilmerge.exe so useful that I just had to write about it.

I found a GUID for MERGE,


but I prefer the line command. I insert on build process this rows:

copy /Y "$(TargetDir)" "$(ProjectDir)Build"
call "$(ProjectDir)Build\Merge.bat" $(ProjectDir)
cd "$(ProjectDir)Build"
del *.dll *.pdb Winvs*

In this way, after the build, all dlls are copied on Build folder and the Merge command is called. The merge.bat is the following:

echo %1
%1Build\ILMerge.exe /keyfile:%1Properties\keys.snk /target:library /copyattrs /targetplatform:v4,"C:\Windows\Microsoft.NET\Framework\v4.0.30319" /out:%1Build\final\namedll %1Build\library.dll %1Build\Castle.Core.dll %1Build\Castle.Windsor.dll %1Build\Microsoft.WITDataStore.dll %1Build\Newtonsoft.Json.dll %1Build\Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll

CRM2011 – Errore: The view or chart specified in the dashboard definition is not valid for the specified record type “Entity”

E’ la terza volta che ho questo errore ed ogni volta mi dimentico sempre come risolverlo. Ho deciso di scrivere un post e *tatuarlo” in internet… :-)


Quando “linko” una nuova webresource con un FETCH XML custom ad una entity (che sia linkato come webresource nel Navigation Pane o come IFRAME direttamente nell’entità) ricevo il messaggio di errore in oggetto.


Questo problema è dovuto al GUID errato inserito per la DefaultView. Il GUID inserito è corretto ma il tipo di vista selezionato non è DefaultView.


Aprire dalla Solution l’entità, selezionare la sezione Views, selezionare il link della Default View.

Dal link estrarre il GUID ed inserirlo nella nostra WebResource.

CRM2013 – Multilookup: Modify the code CRM2011

I migrated the solutions from CRM2011 to CRM2013 but I found a big problem with Multilookup: It does not work…  I tryed to use the solution inside this post but does not work..

Customer type Lookups in Dynamics CRM have always been an interesting and powerful feature that allows you to associate records of multiple entities with entities like Cases, Orders, etc. PartyList Lookups are similar to Customer type lookups, except for the fact that it allows you to have access to a vast array of entities. They are generally available in Activities like Appointments, Phone Calls, etc.

Sometime or the other, you might have had the requirement to modify customer type lookup in CRM to restrict records to a particular entity. For example, you might want to restrict the end user from selecting Accounts while placing an Order from the “Customer” Lookup. Well, there’s a way to achieve that in CRM using JavaScript. It isn’t exactly a supported one. But chances of Rollups breaking it is very less.


Things are a bit different in CRM 2013. In CRM 2011 and even CRM 4.o, the DOM was a litte bit different. But CRM 2013 has its own brand new DOM structure. So, the code differs from that of CRM 2011. If you simply want to get to the code to implement, you can move directly to the next section. If you want to know why that code is required, read on.

Consider we want to restrict the Cusom lookup to a specific entity, Account. If you’re using Internet Explorer, press F12 to open up the Developer Tools. Search for “new_testfield_i” and you’ll find something as follows.


Now, this “new_testfield_i” is basically the magnifying glass image in the “TestField” lookup button. It consists some interesting properties that determine what entities will be displayed in the lookup form. However, we are interested in only a handful of them in order to get our job done. They are “lookuptypes”, “lookuptypeIcons”, “lookuptypenames” and “defaulttype”. Having a closer look at them pretty much explains what each property signifies.

So, now that we have identified what needs to be changed where, let’s get to the coding part of it. Basically, the idea here is to append “_i” after the Customer type lookup field name. Once you get that element, change its properties to get the desired result.

If you have followed the earlier section, you’d know why the following code snippet is required and what exactly it does. Just to be on the same page, the following code will allow only “Account” records to be displayed in the “Regarding” lookup field (in the Phone Call entity).

document.getElementById("new_testfield_i").setAttribute("lookuptypes", "1");
document.getElementById("new_testfield_i").setAttribute("lookuptypeIcons", "/_imgs/ico_16_1.gif");
document.getElementById("new_testfield_i").setAttribute("lookuptypenames", "account:1:Account");
document.getElementById("new_testfield_i").setAttribute("defaulttype", "1");

Well, don’t think it’s done yet! Although the above code might work most of the times, you might find it failing sometimes. Why? Because the entire DOM of Dynamics CRM 2013 is loaded in an asynchronous manner. Hence, the point where your script executes, the field “Regarding” might not have been rendered yet! Let’s add this small fix for it to work perfectly.

setTimeout(function() {
document.getElementById("new_testfield_i").setAttribute("lookuptypes", "1");
document.getElementById("new_testfield_i").setAttribute("lookuptypeIcons", "/_imgs/ico_16_1.gif");
document.getElementById("new_testfield_i").setAttribute("lookuptypenames", "account:1");
document.getElementById("new_testfield_i").setAttribute("defaulttype", "1");
}, 1000);

Now, that was if you wanted to restrict a Customer lookup field to a single entity. What do you do if you want to allow multiple entities, and restrict only a few? It’s simple. See the following code to get it.

setTimeout(function() {
document.getElementById("new_testfield_i").setAttribute("lookuptypes", "1,2");
document.getElementById("new_testfield_i").setAttribute("lookuptypeIcons", "/_imgs/ico_16_1.gif?ver=-475068199:/_imgs/ico_16_2.gif");
document.getElementById("new_testfield_i").setAttribute("lookuptypenames", "account:1:Account,contact:2:Contact");
document.getElementById("new_testfield_i").setAttribute("defaulttype", "1");
}, 1000);

The result now is as follows with Account and Contact being the only allowed Entities.



CRM2011 – Update Rollup 18 is Released!

Update Rollup 18 for Microsoft Dynamics CRM 2011 is available, the KB article related to this release:

Download Link:

Some  important issues that this UR fixed:

  • If a user’s logon domain is different from the Fully Qualified Domain Name, Deployment Manager crashes while opening.
  • When a Managed Solution is imported that updates an existing solution that contains customizations from another Managed Solution, not all labels included in the update are applied to the system.

CRM2011 – Opening Records Created From Dialogs

The daily problem was to open the entity that I created in Dialog. If a user needs to interact with the record right away, then it is very frustrating to have to search and open it after the dialog is completed.
 Automatically presenting the newly created record from a dialog would take custom code.  However, allowing the user to click on a link to open up the record is very easy to do!
  1. Create a dialog and the desired steps
  2. At the end of the dialog create a new page (this step must be after the create record steps, otherwise there will be no record to open)
  3. Create a prompt and response question
  4. In the Prompt text, click on “insert hyperlink”Unbenannt1
  5. In the URL field of the hyperlink, find the new record in the “Look for” dropdown and select the Record URL (Dynamic) field:
    Snap 2014-11-03 at 15.15.08
  6. Name the hyperlink, save and publish the dialogUsers can now run the dialog and open the newly created record at the end:
    Snap 2014-11-03 at 15.18.36