/// <summary> /// Updates the state status. /// </summary> /// <param name="logicalName">Name of the logical.</param> /// <param name="id">The id.</param> /// <param name="state">The state.</param> /// <param name="status">The status.</param> public void UpdateStateStatus(string logicalName, Guid id, ICrmKeyValueAttribute state, ICrmKeyValueAttribute status) { try { this.crmService.Execute(new SetStateDynamicEntityRequest { Entity = new Moniker { Id = id, Name = logicalName }, Status = status.Key, State = state.Value, }); } catch (Exception e) { ConditionalLog.Error("Couldn't update entity state and status", e, this); if (!e.Message.Contains("is not a valid status code for state code")) { return; } ConditionalLog.Info("Trying to set only state", this); try { this.crmService.Execute(new SetStateDynamicEntityRequest { Entity = new Moniker { Id = id, Name = logicalName }, Status = status.Key, State = state.Value, }); } catch { ConditionalLog.Error("Couldn't update entity state", e, this); } } }
/// <summary> /// Updates the state status. /// </summary> /// <param name="logicalName">Name of the logical.</param> /// <param name="id">The id.</param> /// <param name="state">The state.</param> /// <param name="status">The status.</param> private void UpdateStateStatus(string logicalName, Guid id, ICrmKeyValueAttribute state, ICrmKeyValueAttribute status) { try { this.organizationServiceCache.GetOrganizationService().Execute(new SetStateRequest { EntityMoniker = new EntityReference(logicalName, id), State = new OptionSetValue(state.Key), Status = new OptionSetValue(status.Key) }); } catch (Exception e) { ConditionalLog.Error("Couldn't update entity state and status", e, this); if (!e.Message.Contains("is not a valid status code for state code")) { return; } ConditionalLog.Info("Trying to set state only", this); try { this.organizationServiceCache.GetOrganizationService().Execute(new SetStateRequest { EntityMoniker = new EntityReference(logicalName, id), State = new OptionSetValue(state.Key), Status = new OptionSetValue(-1) }); } catch { ConditionalLog.Error("Couldn't update entity state", e, this); } } }
/// <summary> /// Attributes the collection adapter initialized. /// </summary> protected void AttributeCollectionAdapterInitialized() { this.initialState = this.State; this.initialStatus = this.Status; }