Skip to content

Commit 3d77c34

Browse files
authored
Merge pull request #5 from Fellowmind/release/25.10.21
fetch xml api helper, hierarchy tool
2 parents cb0ffd3 + e39c90b commit 3d77c34

File tree

24 files changed

+10803
-19
lines changed

24 files changed

+10803
-19
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.ServiceModel;
5+
using Microsoft.Xrm.Sdk;
6+
using Microsoft.Xrm.Sdk.Query;
7+
using Newtonsoft.Json;
8+
9+
namespace FetchXMLHelperAPI
10+
{
11+
public class FetchXMLHelper : IPlugin
12+
{
13+
public void Execute(IServiceProvider serviceProvider)
14+
{
15+
// Obtain the tracing service
16+
ITracingService tracingService =
17+
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
18+
19+
// Obtain the execution context from the service provider.
20+
IPluginExecutionContext context = (IPluginExecutionContext)
21+
serviceProvider.GetService(typeof(IPluginExecutionContext));
22+
23+
//Create an Organization Service
24+
IOrganizationServiceFactory serviceFactory = serviceProvider.GetService(typeof(IOrganizationServiceFactory)) as IOrganizationServiceFactory;
25+
IOrganizationService service = serviceFactory.CreateOrganizationService(null);
26+
27+
try
28+
{
29+
tracingService.Trace("Starting FetchXMLHelper");
30+
// get the input parameters
31+
string fetchXML = (string)context.InputParameters["FetchXML"];
32+
33+
tracingService.Trace("FetchXML: " + fetchXML);
34+
35+
// create the FetchXML query to dataverse
36+
var query = new FetchExpression(fetchXML);
37+
38+
EntityCollection results = service.RetrieveMultiple(query);
39+
tracingService.Trace("Number of records retrieved: " + results.Entities.Count);
40+
41+
List<Dictionary<string, object>> records = new List<Dictionary<string, object>>();
42+
43+
foreach (var entity in results.Entities)
44+
{
45+
var entityDict = new Dictionary<string, object>();
46+
47+
foreach (var attr in entity.Attributes)
48+
{
49+
string key = attr.Key;
50+
object value = attr.Value;
51+
52+
// Handle lookup logical name
53+
if (entity.Attributes.ContainsKey(key + "@Microsoft.Dynamics.CRM.lookuplogicalname"))
54+
{
55+
entityDict[key + "_logicalName"] = entity.Attributes[key + "@Microsoft.Dynamics.CRM.lookuplogicalname"];
56+
}
57+
58+
// Handle formatted value
59+
if (entity.FormattedValues.ContainsKey(key))
60+
{
61+
entityDict[key + "_formatted"] = entity.FormattedValues[key];
62+
}
63+
64+
entityDict[key] = value;
65+
}
66+
67+
records.Add(entityDict);
68+
}
69+
70+
// If you want to output as JSON:
71+
string outputJson = JsonConvert.SerializeObject(records, Formatting.Indented);
72+
context.OutputParameters["output"] = outputJson;
73+
74+
75+
}
76+
catch (Exception ex)
77+
{
78+
throw new InvalidPluginExecutionException(ex.Message);
79+
80+
}
81+
}
82+
}
83+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{CA0348AE-31E3-4F09-99FF-5FA631BE83CD}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>FetchXMLHelperAPI</RootNamespace>
11+
<AssemblyName>FetchXMLHelperAPI</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<PropertyGroup>
34+
<SignAssembly>true</SignAssembly>
35+
</PropertyGroup>
36+
<PropertyGroup>
37+
<AssemblyOriginatorKeyFile>fellowmind_snk.snk</AssemblyOriginatorKeyFile>
38+
</PropertyGroup>
39+
<ItemGroup>
40+
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
41+
<HintPath>..\..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
42+
</Reference>
43+
<Reference Include="Microsoft.Crm.Sdk.Proxy, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
44+
<HintPath>..\..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.59\lib\net462\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
45+
</Reference>
46+
<Reference Include="Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
47+
<HintPath>..\..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.59\lib\net462\Microsoft.Xrm.Sdk.dll</HintPath>
48+
</Reference>
49+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
50+
<HintPath>..\..\packages\Newtonsoft.Json.13.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
51+
</Reference>
52+
<Reference Include="System" />
53+
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
54+
<HintPath>..\..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
55+
</Reference>
56+
<Reference Include="System.Core" />
57+
<Reference Include="System.DirectoryServices" />
58+
<Reference Include="System.DirectoryServices.AccountManagement" />
59+
<Reference Include="System.IdentityModel" />
60+
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
61+
<HintPath>..\..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
62+
</Reference>
63+
<Reference Include="System.Numerics" />
64+
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
65+
<HintPath>..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
66+
</Reference>
67+
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
68+
<HintPath>..\..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
69+
</Reference>
70+
<Reference Include="System.Runtime.Serialization" />
71+
<Reference Include="System.Security" />
72+
<Reference Include="System.ServiceModel" />
73+
<Reference Include="System.ServiceModel.Http, Version=4.10.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
74+
<HintPath>..\..\packages\System.ServiceModel.Http.4.10.3\lib\net461\System.ServiceModel.Http.dll</HintPath>
75+
</Reference>
76+
<Reference Include="System.ServiceModel.Primitives, Version=4.10.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
77+
<HintPath>..\..\packages\System.ServiceModel.Primitives.4.10.3\lib\net461\System.ServiceModel.Primitives.dll</HintPath>
78+
</Reference>
79+
<Reference Include="System.ServiceModel.Web" />
80+
<Reference Include="System.Text.Encodings.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
81+
<HintPath>..\..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath>
82+
</Reference>
83+
<Reference Include="System.Text.Json, Version=8.0.0.5, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
84+
<HintPath>..\..\packages\System.Text.Json.8.0.5\lib\net462\System.Text.Json.dll</HintPath>
85+
</Reference>
86+
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
87+
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
88+
</Reference>
89+
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
90+
<HintPath>..\..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
91+
</Reference>
92+
<Reference Include="System.Web" />
93+
<Reference Include="System.Xml.Linq" />
94+
<Reference Include="System.Data.DataSetExtensions" />
95+
<Reference Include="Microsoft.CSharp" />
96+
<Reference Include="System.Data" />
97+
<Reference Include="System.Net.Http" />
98+
<Reference Include="System.Xml" />
99+
</ItemGroup>
100+
<ItemGroup>
101+
<Compile Include="FetchXMLHelper.cs" />
102+
<Compile Include="Properties\AssemblyInfo.cs" />
103+
</ItemGroup>
104+
<ItemGroup>
105+
<None Include="app.config" />
106+
<None Include="fellowmind_snk.snk" />
107+
<None Include="packages.config" />
108+
</ItemGroup>
109+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
110+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ProjectView>ShowAllFiles</ProjectView>
5+
</PropertyGroup>
6+
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("FetchXMLHelperAPI")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("HP Inc.")]
12+
[assembly: AssemblyProduct("FetchXMLHelperAPI")]
13+
[assembly: AssemblyCopyright("Copyright © HP Inc. 2025")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("ca0348ae-31e3-4f09-99ff-5fa631be83cd")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
[assembly: AssemblyVersion("1.0.0.0")]
33+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
8+
</dependentAssembly>
9+
</assemblyBinding>
10+
</runtime>
11+
</configuration>
596 Bytes
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net462" />
4+
<package id="Microsoft.CrmSdk.CoreAssemblies" version="9.0.2.59" targetFramework="net462" />
5+
<package id="Newtonsoft.Json" version="13.0.4" targetFramework="net462" />
6+
<package id="System.Buffers" version="4.5.1" targetFramework="net462" />
7+
<package id="System.Memory" version="4.5.5" targetFramework="net462" />
8+
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net462" />
9+
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net462" />
10+
<package id="System.ServiceModel.Http" version="4.10.3" targetFramework="net462" />
11+
<package id="System.ServiceModel.Primitives" version="4.10.3" targetFramework="net462" />
12+
<package id="System.Text.Encodings.Web" version="8.0.0" targetFramework="net462" />
13+
<package id="System.Text.Json" version="8.0.5" targetFramework="net462" />
14+
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net462" />
15+
<package id="System.ValueTuple" version="4.5.0" targetFramework="net462" />
16+
</packages>

0 commit comments

Comments
 (0)