I've found several ways to do stuff that’s like this, but nothing works...
Right now I've have trouble just do set/update a form attribute.
Here my code:
using System; using Microsoft.Xrm.Sdk; using System.ServiceModel; using Microsoft.Xrm.Sdk.Query; using Microsoft.Crm.Sdk.Messages; namespace inexPlugins { public class TimeSpentOnCase: IPlugin { public void Execute(IServiceProvider serviceProvider) { //Extract the tracing service for use in debugging sandboxed plug-ins. ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); // Obtain the execution context from the service provider. IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Entity entity = context.InputParameters["Target"] as Entity; if (entity.LogicalName != "incident") { return; } try { // Obtain the organization service reference. IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); if (entity.Attributes.Contains("new_cField")) { entity.Attributes["new_cField"] = 999; service.Update(entity); } } catch (FaultException<OrganizationServiceFault> ex) { throw new InvalidPluginExecutionException("An error occurred in the plug-in for calculating time spent on a case.", ex); } catch (Exception ex) { tracingService.Trace("TimeSpentOnCase: {0}", ex.ToString()); throw; } } } } }
/ inexHalSoul