Hi,
I've developed a Custom Workflow Activity which has the output parameter of type EntityReference. Using this output parameter to update the related entity's field. It's not actually updating the record for some weird reason. Debugged the CWA code to confirm that correct EntityReference is being returned and set to the output parameter.
Here is the code:
using System; using System.Activities; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Sdk.Workflow; namespace MSCRM.Workflow { public class GetServiceOpsUser : CodeActivity { [Input("Client Executive")] [RequiredArgument] [ReferenceTarget("systemuser")] public InArgument<EntityReference> CE { get; set; } [Output("Ops User")] [ReferenceTarget("systemuser")] public OutArgument<EntityReference> OpsUser { get; set; } protected override void Execute(CodeActivityContext executionContext) { try { // Create the tracing service ITracingService tracingService = executionContext.GetExtension<ITracingService>(); tracingService.Trace("Begin GetServiceOpsUser:" + DateTime.Now.ToString()); // Create the context IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>(); if (context != null) { tracingService.Trace("Context created."); } IOrganizationServiceFactory ServiceFactory = executionContext.GetExtension<IOrganizationServiceFactory>(); // Create the Organiztion service IOrganizationService service = ServiceFactory.CreateOrganizationService(context.UserId); if (service != null) { tracingService.Trace("Organization Service created."); } tracingService.Trace("Begin as UserId: " + context.UserId.ToString() + DateTime.Now.ToString()); // Get 'Client Executive' from Input Parameters EntityReference erCE = CE.Get(executionContext); // Get 'Client Executive' if (erCE != null && erCE.Id != null && erCE.Id != Guid.Empty) { tracingService.Trace("Client Executive: " + erCE.Name); // Get Client Executive Manager Entity eCE = service.Retrieve("systemuser", erCE.Id, new ColumnSet(new String[] { "parentsystemuserid" })); if (eCE != null && eCE.Contains("parentsystemuserid") && ((EntityReference)eCE["parentsystemuserid"]) != null) { EntityReference erCEManager = eCE["parentsystemuserid"] as EntityReference; tracingService.Trace("Client Executive's Manager: " + erCEManager.Name); // Get CE Manager's Business Unit if (erCEManager.Id != null && erCEManager.Id != Guid.Empty) { Entity eCEManager = service.Retrieve("systemuser", erCEManager.Id, new ColumnSet(new string[] { "sir_serviceopsuser" })); if (eCEManager != null && eCEManager.Contains("sir_serviceopsuser") && ((EntityReference)eCEManager["sir_serviceopsuser"]) != null) { EntityReference erServiceOpsUser = eCEManager["sir_serviceopsuser"] as EntityReference; tracingService.Trace("Manager's Service Ops User: " + erServiceOpsUser.Name); // Set Output parameter named 'Service Ops User' OpsUser.Set(executionContext, new EntityReference(erServiceOpsUser.LogicalName, erServiceOpsUser.Id)); tracingService.Trace("Output parameter set as " + erServiceOpsUser.Name); } } } } else { tracingService.Trace("End GetServiceOpsUser:" + DateTime.Now.ToString()); return; } tracingService.Trace("End GetServiceOpsUser:" + DateTime.Now.ToString()); } catch (System.Web.Services.Protocols.SoapException ex) { throw new InvalidPluginExecutionException(string.Format("An error occurred in the 'GetServiceOpsUser' Custom Workflow Activity. Message: {0}", ex.Message), ex); } catch (Exception ex) { throw new InvalidPluginExecutionException(string.Format("An error occurred in the 'GetServiceOpsUser' Custom Workflow Activity. Message: {0}", ex.Message), ex); } } } }
Correctly using the Output parameter in the process designer. However it's not working as expected.
Any suggestions are highly appreciated!
Thank you!
Best regards,
Abhi