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.
To prepare your plugins for integration, implement the IMessageBusHost
interface in both source and target plugins.
public partial class DataUpdater : PluginBase, IGitHubPlugin, IPayPalPlugin, IMessageBusHost
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.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.
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.