First of all, why would you need to build a plugin in the XrmToolBox? Isn’t it what the Visual Studio is for?
I think the answer is “yes and no”. See, if you are a developer and have all the tools.. you probably don’t need to read this post (other than out of curiosity). But, if you are a Dynamics administrator, or, maybe, you are a developer who just needs to create a plugin quickly while you are away from your work computer.. Whatever the reason is, if you do need to create a plugin for Dynamics, and if you don’t have Visual Studio installed, you can do it with the CodeNow plugin easily now.
Before you continue, you may want to get CodeNow plugin installed, so here is where you’ll find the instructions:
http://www.itaintboring.com/tcs-tools/code-now-plugin-for-xrmtoolbox/
Once you have it installed, the process looks like this:
- Using XrmToolBox, you can build a plugin
- And, then, you can use PluginRegistrationTool to register the plugin
For the plugin registration tool, you will find a detailed walkthrough here:
https://msdn.microsoft.com/en-us/library/gg309580.aspx
In this post, I’ll walk you through the steps required to compile a plugin in XrmToolBox.
Here we go:
1. Open XrmToolBox and load CodeNow plugin
2. Select “Plugin” checkbox
Once you have selected the checkbox, CodeNow will display sample plugin code. You can actually use “Compile” command to compile plugin dll at this point, but it won’t, really, be very functional yet.
However, that sample code has all the basic code you need to start with..
So, why don’t we create a plugin for the account entity that will ensure that nobody will set account name to “Test”
3. Here is the code we are going to add
if(entity.Contains("name") && (string)entity["name"] == "Test") throw new InvalidPluginExecutionException("Cannot use 'Test' for the account name");
4. It’s time to compile the plugin?
When you click “Compile”, the tool will ask you for the dll file name, so.. just choose the file name you want. “Test.dll” might be just fine:
5. Now you can use the PluginRegistrationTool to register the plugin
And the SDK step, of course:
6. And, now, let’s do a quick test. Let’s try to update the account’s name:
Worked out just as we planned!
Why not stay in the box all the way – use PluginRegistration tool for XrmToolBox instead of the SDK version! 🙂
Jonas, you are right – I should have used XrmToolBox version instead:)
When checking the Plugin checkbox the inserted code in the area with the fetchXml is reset. It seems to be a bug. Can you please confirm.
Hi Henrik,
it’s not so much a bug, bit it’s a design issue.. plugin code is very different from “run now” or executable, so the code can’t be reused when “plugin” option is selected. Still need to figure out how to do it in a better way(any suggestions?)
Hi Alex, is so useful to me this tool !! especially rapid changes or queries and for generating small exes
When I tried the plugin for 2011 installations, it failed in the registration process. The CRM libraries that you are using aren’t from 2011 version. Are you planning to make it compatible for 2011/2013 versions, or is there a workaround for 2011 plugins .
Regards and keep improving !
Hi Gabriel,
this plugin is for 365.. for 2011 etc it may not really work in the XrmToolBox because of the referenced assemblies, .NET FW version, etc. Maybe as a standalone tool, if I ever get to that:)