Using Resx file in D365 Plugins/Workflows
- Get link
- X
- Other Apps
Usage of Resx file in D365 Plugins/Workflows:
Most of the times, we use fetchxml queries in the plugins and workflows to retrieve the entity data and we directly hardcode these queries in the retrieve methods. Instead we can use Resources file(.resx) to store all the fetchxml in common file and use it wherever it is required. This helps in maintaining the code and also promotes reusability.
Creation of Resx File:
Below is the sample Plugin project I have created to explain the usage of Resx file.
Once the project is created, add new resource file named as "FetchXML.resx" as shown below.
After the file is added to the project, open the "FetchXML.resx" file from solution explorer.
Add the Name and Fetchxml under the value as shown below. For filter conditions, you can use some placeholders(eg: {EmailAddress}) and replace after you retrieve the Fetchxml string from resource file.
Once added save this file.
In the plugin code, fetchxml can be retrieved from resource file using the following code.
Sample code snippet for retrieving the fetchxml from resource file and using in the plugin.
// Retrieve the AccountFetchXML from Resource file.
string accountFetchXML = TestPlugin.FetchXML.ResourceManager.GetString("GetAccountbyEmail", CultureInfo.InvariantCulture);
// Replace condition values.
accountFetchXML = accountFetchXML.Replace("{EmailAddress}", email);
// Execute the fetchxml query.
EntityCollection accountCollection = service.RetrieveMultiple(new FetchExpression(accountFetchXML));
- Get link
- X
- Other Apps
Comments
Post a Comment