I have a custom workflow that seems to be working (it updates the lead) but receives an Invalid Argument error. After putting in various traces and getting no output from them I commented out all of the code that could be causing the problem. I still get the error message. The message text is...
Plugin Trace:
[Microsoft.Xrm.Sdk.Workflow: Microsoft.Xrm.Sdk.Workflow.Activities.RetrieveEntity]
[RetrieveEntity]
Error Message:
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Expected non-empty Guid.Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147220989</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>Expected non-empty Guid.</Message>
<Timestamp>2013-05-24T16:43:29.5240702Z</Timestamp>
<InnerFault>
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:d3p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>System.ArgumentException: Expected non-empty Guid.
Parameter name: id</Message>
<Timestamp>2013-05-24T16:43:29.5240702Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText i:nil="true" />
</InnerFault>
<TraceText>[Microsoft.Xrm.Sdk.Workflow: Microsoft.Xrm.Sdk.Workflow.Activities.RetrieveEntity]
[RetrieveEntity]
</TraceText>
</OrganizationServiceFault>
at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Retrieve(String entityName, Guid id, ColumnSet columnSet, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)
at Microsoft.Crm.Extensibility.InprocessServiceProxy.RetrieveCore(String entityName, Guid id, ColumnSet columnSet)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.Retrieve(String entityName, Guid id, ColumnSet columnSet)
at Microsoft.Crm.Workflow.Services.RetrieveActivityService.<>c__DisplayClass1.<RetrieveInternal>b__0(IOrganizationService sdkService)
at Microsoft.Crm.Workflow.Services.ActivityServiceBase.ExecuteInTransactedContext(ActivityDelegate activityDelegate)
at Microsoft.Crm.Workflow.Services.RetrieveActivityService.ExecuteInternal(ActivityContext executionContext, RetrieveEntity retrieveEntity)
at Microsoft.Crm.Workflow.Services.RetrieveActivityService.Execute(ActivityContext executionContext, RetrieveEntity retrieveEntity)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Here is the current code...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Activities; using System.Runtime.Serialization; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Messages; using Microsoft.Xrm.Sdk.Workflow; using Microsoft.Xrm.Sdk.Query; using Microsoft.Crm.Sdk.Messages; namespace CrmAssignTerritories { public class AssignAccountTerritory : CodeActivity { [Input("string input")] public InArgument<string> ZipCode { get; set; } //[Output("EntityReference output only")] //[ReferenceTarget("systemuser")] //public OutArgument<EntityReference> Territory { get; set; } protected override void Execute(CodeActivityContext executionContext) { Boolean zipCodeFound = false; String searchZipCode; Guid territoryGuid = new Guid(); IWorkflowContext workflowContext = executionContext.GetExtension<IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId); //Create the tracing service ITracingService tracingService = executionContext.GetExtension<ITracingService>(); tracingService.Trace("Start Assign Account Territory"); /* if (workflowContext.PrimaryEntityName == "account" || workflowContext.PrimaryEntityName == "lead") { String zipCode = ZipCode.Get<string>(executionContext); searchZipCode = zipCode; int zipCodeLength = searchZipCode.Length; String entityName = workflowContext.PrimaryEntityName; Guid entityId = workflowContext.PrimaryEntityId; Entity updateEntity = new Entity(entityName); updateEntity.Id = entityId; do { tracingService.Trace("Query zip code {0}", searchZipCode); QueryByAttribute zipCodeQuery = new QueryByAttribute(); zipCodeQuery.ColumnSet = new ColumnSet("ree_territoryid"); zipCodeQuery.EntityName = "ree_territoryzipcode"; zipCodeQuery.AddAttributeValue("ree_zipcode", searchZipCode); EntityCollection zipCodeCollection = service.RetrieveMultiple(zipCodeQuery); foreach (var zipCodeEntity in zipCodeCollection.Entities) { tracingService.Trace("Zip code found"); territoryGuid = ((EntityReference)zipCodeEntity["ree_territoryid"]).Id; zipCodeFound = true; } if (!zipCodeFound) { zipCodeLength--; searchZipCode = searchZipCode.Substring(0, zipCodeLength); } } while (zipCodeLength > 0 && !zipCodeFound); if (!zipCodeFound) { tracingService.Trace("Zip code NOT found"); QueryByAttribute defaultTerritoryQuery = new QueryByAttribute(); defaultTerritoryQuery.ColumnSet = new ColumnSet("territoryid"); defaultTerritoryQuery.EntityName = "territory"; defaultTerritoryQuery.AddAttributeValue("name", "DEFAULT"); EntityCollection defaultTerritoryCollection = service.RetrieveMultiple(defaultTerritoryQuery); foreach (var defaultTerritoryEntity in defaultTerritoryCollection.Entities) { tracingService.Trace("Default zip code found"); territoryGuid = defaultTerritoryEntity.Id; } } updateEntity["gsi_territoryrsmid"] = new EntityReference("territory", territoryGuid); service.Update(updateEntity); } */ } } }Thanks for the help!!
Gary