Hi guys, I'm a bit at a loss here. I've never ventured into how these voids work and I need to use variables from one in the other. I want this plugin to only run when 1 of 3 specific people update a Task. The plugin fails if anyone else does it because they don't have permissions to the regarding entity. So I want to catch it and only run with specific people use it.
I found some code that demonstrates how to get the current user id but I'm having issues getting it to work. I get an error message that says 'TaskUpdate.JobCostUpdate.PostTaskUpdate.Execute(System.IServiceProvider)' hides inherited member 'TaskUpdate.JobCostUpdate.Plugin.Execute(System.IServiceProvider)'. Use the new keyword if hiding was intended.'
Code is below. Thanks for any help.
namespace TaskUpdate.JobCostUpdate { using System; using System.Linq; using System.ServiceModel; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Client; using Microsoft.Xrm.Sdk.Query; public class PostTaskUpdate : Plugin { Guid jocelyn = new Guid("ABD80D9F-F3B8-E211-AC09-12A32B1E376A"); Guid trevor = new Guid("E200F73B-57CC-E111-B35F-12A32B1E376A"); Guid Lois = new Guid("2B13D49B-BD82-E311-990D-12A32B1E376A"); Guid userId; public PostTaskUpdate() : base(typeof(PostTaskUpdate)) { base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "task", new Action<LocalPluginContext>(ExecutePostTaskUpdate))); } public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); userId = context.InitiatingUserId; } protected void ExecutePostTaskUpdate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService service = localContext.OrganizationService; var ServiceContext = new OrganizationServiceContext(service); ITracingService tracingService = localContext.TracingService; if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { if (userId == trevor || userId == Lois || userId == jocelyn) { Entity entity = (Entity)context.InputParameters["Target"]; Entity pEntity = service.Retrieve("task", entity.Id, new ColumnSet("new_billingtaskid")); string postImage = ""; if (pEntity.Attributes.Contains("new_billingtaskid")) { postImage = (string)pEntity["new_billingtaskid"]; } if (entity.Attributes.Contains("new_billingtaskid")) { postImage = (string)entity["new_billingtaskid"]; } var res = from q in ServiceContext.CreateQuery("new_salescommissionslineitems") where q["new_billingtask"].Equals(entity.Id) select q; foreach (var q in res) { q["new_jobcostid"] = postImage; ServiceContext.UpdateObject(q); } } ServiceContext.SaveChanges(); } } } }