Created
March 16, 2022 19:01
-
-
Save melamriD365/6afa209ca45a22e99322ab5f5e417ffa to your computer and use it in GitHub Desktop.
Power Automate - Dataverse] How to execute a fetchXml query that includes options not supported by the List rows connector?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <copyright file="Plg_ExecuteFetchXml.cs" company=""> | |
// Copyright (c) 2022 All Rights Reserved | |
// </copyright> | |
// <author></author> | |
// <date>3/14/2022 2:38:36 PM</date> | |
// <summary>Implements the Plg_ExecuteFetchXml Plugin.</summary> | |
// <auto-generated> | |
// This code was generated by a tool. | |
// Runtime Version:4.0.30319.1 | |
// </auto-generated> | |
using System; | |
using System.ServiceModel; | |
using Microsoft.Xrm.Sdk; | |
using Microsoft.Xrm.Sdk.Query; | |
namespace MEA.POC.Plugins | |
{ | |
/// <summary> | |
/// Plg_ExecuteFetchXml Plugin. | |
/// </summary> | |
public class Plg_ExecuteFetchXml: PluginBase | |
{ | |
/// <summary> | |
/// Initializes a new instance of the <see cref="Plg_ExecuteFetchXml"/> class. | |
/// </summary> | |
/// <param name="unsecure">Contains public (unsecured) configuration information.</param> | |
/// <param name="secure">Contains non-public (secured) configuration information. | |
/// When using Microsoft Dynamics 365 for Outlook with Offline Access, | |
/// the secure string is not passed to a plug-in that executes while the client is offline.</param> | |
public Plg_ExecuteFetchXml(string unsecure, string secure) | |
: base(typeof(Plg_ExecuteFetchXml)) | |
{ | |
// TODO: Implement your custom configuration handling. | |
} | |
/// <summary> | |
/// Main entry point for he business logic that the plug-in is to execute. | |
/// </summary> | |
/// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the | |
/// <see cref="IPluginExecutionContext"/>, | |
/// <see cref="IOrganizationService"/> | |
/// and <see cref="ITracingService"/> | |
/// </param> | |
/// <remarks> | |
/// For improved performance, Microsoft Dynamics 365 caches plug-in instances. | |
/// The plug-in's Execute method should be written to be stateless as the constructor | |
/// is not called for every invocation of the plug-in. Also, multiple system threads | |
/// could execute the plug-in at the same time. All per invocation state information | |
/// is stored in the context. This means that you should not use global variables in plug-ins. | |
/// </remarks> | |
protected override void ExecuteCdsPlugin(ILocalPluginContext localContext) | |
{ | |
if (localContext == null) | |
{ | |
throw new InvalidPluginExecutionException(nameof(localContext)); | |
} | |
// Obtain the tracing service | |
ITracingService tracingService = localContext.TracingService; | |
try | |
{ | |
IPluginExecutionContext context = (IPluginExecutionContext)localContext.PluginExecutionContext; | |
IOrganizationService currentUserService = localContext.CurrentUserService; | |
var fetchXml = (string) context.InputParameters["mea_fetchxml"]; | |
var result = currentUserService.RetrieveMultiple(new FetchExpression(fetchXml)); | |
context.OutputParameters["mea_fetchxmlresponse"] = result; | |
} | |
catch (Exception ex) | |
{ | |
tracingService?.Trace("An error occurred executing Plugin MEA.POC.Plugins.Plg_ExecuteFetchXml : {0}", ex.ToString()); | |
throw new InvalidPluginExecutionException("An error occurred executing Plugin MEA.POC.Plugins.Plg_ExecuteFetchXml .", ex); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment