Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36623.8 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActivityLogs.Plugins", "ActivityLogs.Plugins\ActivityLogs.Plugins.csproj", "{C39F5F21-4E07-45ED-972E-2F45962D62AC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C39F5F21-4E07-45ED-972E-2F45962D62AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C39F5F21-4E07-45ED-972E-2F45962D62AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C39F5F21-4E07-45ED-972E-2F45962D62AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C39F5F21-4E07-45ED-972E-2F45962D62AC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CCFA3561-9AF0-4F5A-81C4-ACA08E7CB8B4}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using Microsoft.Xrm.Sdk;

namespace SystemIntake.Plugins
{
public class ActivityLog_Create_SyncTargetStepToReviewAndRequest : IPlugin
{
private const string ActivityLogEntity = "new_activitylogs";

// Activity Log fields
private const string TargetStepField = "new_process_target_step"; // Choice (global)
private const string ReviewLookupField = "new_adminreview"; // Lookup -> cr69a_systemintakeadmin
private const string RequestLookupField = "new_systemintake"; // Lookup -> new_systemintake (Request)

// Review fields
private const string ReviewEntity = "cr69a_systemintakeadmin";
private const string ReviewStepField = "new_admingovernancetasklist"; // Choice (same global)
private const string ReviewReadyForReviewField = "cr69a_readyforreview"; // Two Options (Yes/No)

// Request fields
private const string RequestEntity = "new_systemintake";
private const string RequestStepField = "new_admingovernanceprocessstep"; // Choice (same global)
private const string RequestReadyForReviewField = "cr69a_readyforreview"; // Two Options (Yes/No)

public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context == null) return;

if (!string.Equals(context.PrimaryEntityName, ActivityLogEntity, StringComparison.OrdinalIgnoreCase)) return;
if (!string.Equals(context.MessageName, "Create", StringComparison.OrdinalIgnoreCase)) return;

// PostOperation only
if (context.Stage != 40) return;

object targetObj;
if (!context.InputParameters.TryGetValue("Target", out targetObj)) return;

var target = targetObj as Entity;
if (target == null) return;

var reviewRef = target.GetAttributeValue<EntityReference>(ReviewLookupField);
var requestRef = target.GetAttributeValue<EntityReference>(RequestLookupField);

// Step is optional now (we still want to clear Ready for Review even if step isn't set)
var step = target.GetAttributeValue<OptionSetValue>(TargetStepField);

var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.UserId);

// Update Review (if present)
if (reviewRef != null)
{
var reviewUpdate = new Entity(ReviewEntity, reviewRef.Id);

// Sync step only if provided on the log
if (step != null)
{
reviewUpdate[ReviewStepField] = new OptionSetValue(step.Value);
}

// Always set Ready for Review = false when an Activity Log is created
reviewUpdate[ReviewReadyForReviewField] = false;

service.Update(reviewUpdate);
}

// Update Request (if present)
if (requestRef != null)
{
var requestUpdate = new Entity(RequestEntity, requestRef.Id);

// Sync step only if provided on the log
if (step != null)
{
requestUpdate[RequestStepField] = new OptionSetValue(step.Value);
}

// Always set Ready for Review = false when an Activity Log is created
requestUpdate[RequestReadyForReviewField] = false;

service.Update(requestUpdate);
}
Comment on lines 30 to 179
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This plugin updates two related records but has no ITracingService logging. Add tracing (IDs for Activity Log / Review / Request, whether step was present, and update outcomes) so support can troubleshoot failures (permissions, missing references) using plugin trace logs.

Copilot uses AI. Check for mistakes.
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

namespace SystemIntake.Plugins
{
public class ActivityLog_Create_ValidateTargetStepNotCurrent : IPlugin
{
private const string ActivityLogEntity = "new_activitylogs";

// Activity Log fields
private const string TargetStepField = "new_process_target_step"; // Choice (global)
private const string ReviewLookupField = "new_adminreview"; // Lookup -> cr69a_systemintakeadmin

// Review fields
private const string ReviewEntity = "cr69a_systemintakeadmin";
private const string ReviewStepField = "new_admingovernancetasklist"; // Choice (same global)

public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context == null) return;

if (!string.Equals(context.PrimaryEntityName, ActivityLogEntity, StringComparison.OrdinalIgnoreCase)) return;
if (!string.Equals(context.MessageName, "Create", StringComparison.OrdinalIgnoreCase)) return;

// PreOperation only
if (context.Stage != 20) return;

object targetObj;
if (!context.InputParameters.TryGetValue("Target", out targetObj)) return;

var target = targetObj as Entity;
if (target == null) return;

var step = target.GetAttributeValue<OptionSetValue>(TargetStepField);
if (step == null) return; // if no step provided, nothing to validate

var reviewRef = target.GetAttributeValue<EntityReference>(ReviewLookupField);
if (reviewRef == null) return; // if no review link, nothing to validate

var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.UserId);

var review = service.Retrieve(ReviewEntity, reviewRef.Id, new ColumnSet(ReviewStepField));
var current = review.GetAttributeValue<OptionSetValue>(ReviewStepField);

if (current != null && current.Value == step.Value)
{
throw new InvalidPluginExecutionException(
"That step is already the current step. Please choose a different target step."
);
}
Comment on lines 20 to 149
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This plugin performs an IOrganizationService.Retrieve but has no ITracingService logging. Adding tracing around the retrieve and the comparison (and before throwing) will make it much easier to diagnose permission issues or unexpected data in Dataverse plugin trace logs.

Copilot uses AI. Check for mistakes.
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using Microsoft.Xrm.Sdk;

namespace SystemIntake.Plugins
{
public class ActivityLog_Update_BlockAll : IPlugin
{
private const string ActivityLogEntity = "new_activitylogs";

public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context == null) return;

if (!string.Equals(context.PrimaryEntityName, ActivityLogEntity, StringComparison.OrdinalIgnoreCase)) return;
if (!string.Equals(context.MessageName, "Update", StringComparison.OrdinalIgnoreCase)) return;

// PreOperation only
if (context.Stage != 20) return;

// If you want to allow SYSTEM/INTEGRATION updates, you can add exceptions here later.
throw new InvalidPluginExecutionException(
"Activity Logs are immutable and cannot be updated. Create a new Activity Log entry instead."
);
Comment on lines 13 to 35
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These plugins don’t use ITracingService at all. The repo’s plugin guide recommends tracing for diagnostics, and the existing plugins use it. Consider adding basic trace statements (start/end, key IDs, and before throwing exceptions) to make production troubleshooting feasible.

Copilot uses AI. Check for mistakes.
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C39F5F21-4E07-45ED-972E-2F45962D62AC}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ActivityLogs.Plugins</RootNamespace>
<AssemblyName>ActivityLogs.Plugins</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>SystemIntake.Plugins.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Crm.Sdk.Proxy, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.60\lib\net462\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.60\lib\net462\Microsoft.Xrm.Sdk.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.DirectoryServices" />
<Reference Include="System.DirectoryServices.AccountManagement" />
<Reference Include="System.IdentityModel" />
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Http, Version=4.10.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.ServiceModel.Http.4.10.3\lib\net461\System.ServiceModel.Http.dll</HintPath>
</Reference>
<Reference Include="System.ServiceModel.Primitives, Version=4.10.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.ServiceModel.Primitives.4.10.3\lib\net461\System.ServiceModel.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Text.Encodings.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath>
</Reference>
<Reference Include="System.Text.Json, Version=8.0.0.5, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Json.8.0.5\lib\net462\System.Text.Json.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActivityLog_Create_SyncTargetStepToReviewAndRequest.cs" />
<Compile Include="ActivityLog_Update_BlockAll.cs" />
<Compile Include="ActivityLog_Create_ValidateTargetStepNotCurrent.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="SystemIntake.Plugins.snk" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ActivityLogs.Plugins")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ActivityLogs.Plugins")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c39f5f21-4e07-45ed-972e-2f45962d62ac")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading