With the next release of FetchXML Builder for XrmToolBox it is possible for other tools to benefit from the UI FetchXML Builder offers to compose queries to be used for any purpose.
The MessageBus functionality introduced in pull request #101 of XrmToolBox makes it possible to communicate between plugins within the tool.
This is implemented in the Bulk Data Updater (currently available as beta in Cinteros’ set of tools for XrmToolBox at http://cinteros.xrmtoolbox.com) to be able to use FetchXML Builder to get the query to use when retrieving records to update.
Using the MessageBus, it is really easy to get FXB to do the work for you when you need a FetchXML string or a QueryExpression object in your plugin. When communicating with FXB, the argument passed between the plugins shall be an instance of FXBMessageBusArgument, which is a public class in the FXB assembly.
Preparation
To prepare your plugins for integration, implement the IMessageBusHost interface in both source and target plugins.
public partial class DataUpdater : PluginBase, IGitHubPlugin, IPayPalPlugin, IMessageBusHost
Sample call to start FXB
Clickin the button in the above image will execute the following code:
var messageBusEventArgs = new MessageBusEventArgs("FetchXML Builder"); messageBusEventArgs.TargetArgument = new FXBMessageBusArgument(FXBMessageBusRequest.FetchXML) { FetchXML = internalFetchXml }; OnOutgoingMessage(this, messageBusEventArgs);
This will start FetchXML Builder with a new button in the toolbar – “Return FetchXML”. FXB will be initiated with the current FetchXML stored in the internalFetchXml variable in Bulk Data Updater.
Sample method to receive query from FXB
When the return-button is clicked in FetchXML Builder, a similar MessageBus event is triggered in the calling plugin.
public void OnIncomingMessage(MessageBusEventArgs message) { if (message.SourcePlugin == "FetchXML Builder" && message.TargetArgument is FXBMessageBusArgument) { var fxbArg = (FXBMessageBusArgument)message.TargetArgument; internalFetchXml = fxbArg.FetchXML; } }
The MessageBuEventArgs in this event now contains a TargetArgument of type FXBMessageBusArgument. Depending on the request that was made to FetchXML Builder, the argument till contain a FetchXML string or a QueryExpression object.
Timeline
When writing this blog, a public release of XrmToolBox and FetchXML Builder including MessageBus functionality is not yet available. Tanguy Touzard, author of XrmToolBox, plans to have this release available for the public “early May”. FetchXML Builder supporting this functionality will be available at the same time, or shortly after.
However:
- The MessageBus functionality is implemented in XrmToolBox and available from the XrmToolBox GitHub repository.
- The FXBMessageBusArgument class is implemented and available from the FetchXML Builder GitHub repository.
This means that plugins with the need to use FXB to compose their queries can also be implemented now, to be able to release the plugins when the MessageBus framework is released to public. The easiest way to get the FXB interface is to download the draft release available at GitHub and reference the FXB assembly in your plugin.
Background
- XrmToolBox is the toolkit to use to survive the everyday challenges for Microsoft Dynamics CRM administrators, customizers and developers. XrmToolBox can be downloaded from http://www.xrmtoolbox.com
- FetchXML Builder is one of about 40 publicly available tools for XrmToolBox. FetxhXML Builder can be downloaded from http://fxb.xrmtoolbox.com
- Bulk Data Updater is one of the tools for XrmToolBox from Cinteros AB currently in beta release. Cinteros toolkit can be downloaded from http://cinteros.xrmtoolbox.com
Note – if you would like to see an OData query string returned from FetchXML Builder, make sure you vote up issue #4 on GitHub!
One thought on “Integrating FetchXML Builder with other plugins”