2016-08-11 6 views
1

私は、CRMプロセスに由来するワークフローアクティビティを行っています。 私はEntityReferenceであり、処理中に入力されている2つの入力を持っています。 試行後のトレースを印刷しないでください。ちょうどキャッチを入力します。そして私は理由を知っている。 私のコードは次のとおりです。CRM - ワークフローアクティビティ - エラー:指定されたキーが辞書に存在しませんでした。

public class WK_DecorrerObjetivo : CodeActivity 
{ 
    //inputs dialog --- // input alvo 
    [Input("Alvo")] 
    [ReferenceTarget("xpto_alvo")] 
    public InArgument<EntityReference> alvo { get; set; } 

    //input actividade xpto_atividadeobjetivoid 
    [Input("Actividade Objetivo")] 
    [ReferenceTarget("xpto_atividadedeobjetivo")] 
    public InArgument<EntityReference> atividadeObjetivo { get; set; } 

    protected override void Execute(CodeActivityContext Execontext) 
    { 

     ITracingService _tracing; 
     IWorkflowContext context = null; 
     IOrganizationServiceFactory serviceFactory = null; 
     IOrganizationService service = null; 
     OrganizationServiceContext serviceContext = null; 

     try 
     { 
      #region Get Work Flow Context 

      context = Execontext.GetExtension<IWorkflowContext>(); 
      serviceFactory = Execontext.GetExtension<IOrganizationServiceFactory>(); 
      service = serviceFactory.CreateOrganizationService(context.InitiatingUserId); 
      serviceContext = new OrganizationServiceContext(service); 

      _tracing = Execontext.GetExtension<ITracingService>(); 
      _tracing.Trace("inicio do try"); 

      FetchExpression query = new FetchExpression(string.Format(Resources.GetTemplateAtividade, context.PrimaryEntityId)); 

      // Obtain result from the query expression. 
      Entity new_alvo = (Entity)context.InputParameters["Target"]; 
      var alvoGUID = ((EntityReference)new_alvo["xpto_alvo"]).Id; 
      Entity retrieveTemp = service.Retrieve("xpto_alvo", ((EntityReference)new_alvo["xpto_alvo"]).Id, new ColumnSet("xpto_utilizador", "xpto_conta", "xpto_contacto", "xpto_alvoid", "xpto_name", "createdon", "xpto_estado", "xpto_resultadoimportacao", "xpto_objetivoassociadoid", "xpto_alvo")); 

      OptionSetValue tipoAtividade = (OptionSetValue)retrieveTemp.Attributes["xpto_tipoatividade"]; 
       switch (tipoAtividade.Value) 
       { 
       case 0: 
        _tracing.Trace("entrou no case 0 - compromisso"); 

        break; 

       case 1: 
        _tracing.Trace("entrou no case 1 - phonecall"); 

        break; 

       case 2: 
        _tracing.Trace("entrou no case 2 - task"); 
        break; 

       default: 
        break; 
      } 
      //serviceContext.SaveChanges(); _tracing.Trace("savechanges"); 
     } 

     catch (Exception ex) 
     { 
      string msgErro; 

      if (ex.InnerException != null) 
      { 
       msgErro = ex.InnerException.Message; 
      } 
      else 
      { 
       msgErro = ex.Message; 
      } 

      throw new InvalidPluginExecutionException(string.Format("Erro ao decorrer objetivo: {0}", msgErro)); 
     } 

    } 

} 

感謝の。

答えて

0

"xpto_tipoatividade"にアクセスしようとしているオプション設定値は、取得要求でフェッチする列のリストには含まれていません。また、属性が返されたエンティティ属性コレクションに存在し、それを安全にキャストするかどうか、または拡張メソッドを使用してデフォルト値を取得するかどうかを常に確認します。

var retrieveTemp = service.Retrieve("xpto_alvo", 
        ((EntityReference) new_alvo["xpto_alvo"]).Id, 
        new ColumnSet(
        "xpto_tipoatividade", //<-- add xpto_tipoatividade to the list of attributes to fetch 
        "xpto_utilizador", 
        "xpto_conta", 
        "xpto_contacto", 
        "xpto_alvoid", 
        "xpto_name", 
        "createdon", 
        "xpto_estado", 
        "xpto_resultadoimportacao", 
        "xpto_objetivoassociadoid", 
        "xpto_alvo")); 

var tipoAtividade = retrieveTemp.GetAttributeValue<OptionSetValue>("xpto_tipoatividade"); 

if (tipoAtividade == null) 
{ 
    _tracing.Trace("tipoAtividade is null, returning"); 
    return; 
} 
switch (tipoAtividade.Value) 
{ 
    .... 
} 
関連する問題