2010-03-25 20 views
3

我需要爲動態CRM 4.0編寫一個插件,當重新打開關閉的商機以更改銷售代碼時執行該插件。我的問題是:客戶關係管理插件在機會重新開放時執行

  • 當我向插件註冊新的步驟時,應該過濾哪些屬性?
  • 我應該檢查實體的哪些屬性?和
  • 我該如何查找此實體的值才能確定插件執行是否應該繼續?

我通常寫異步工作流和我的經驗編寫插件還在發展,所以我會很感激,可以提供任何幫助和澄清。

請參閱插件骨架下面我寫

public void Execute(IPluginExecutionContext context) 
    { 
     if (context.InputParameters.Properties.Contains("Target") && context.InputParameters.Properties["Target"] is DynamicEntity) 
     { 
      ICrmService service = context.CreateCrmService(false); 

      DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties["Target"]; 

      if (entity.Name == EntityName.opportunity.ToString()) 
      { 
       if (entity.Properties.Contains(/*What Property Should I Check Here?*/)) 
       { 
        //And what value should I be looking for in that property? 

       } 
      } 
     } 
    } 

回答

0

這是我最終到達。我將這個標記爲正確的答案,但是當我能夠再次獲勝時,它們會給你(Focus和Corey)一個滿意的結果,因爲我結合了你們兩個人的建議來達成這個解決方案。

public void Execute(IPluginExecutionContext context) 
    { 
     if (context.InputParameters.Properties.Contains("Target") && 
      context.InputParameters.Properties["Target"] is DynamicEntity) 
     { 
      DynamicEntity opp = (DynamicEntity)context.InputParameters["Target"]; 
      Picklist StageCodePicklist = new Picklist(); (Picklist);opp.Properties["salesstagecode"]; 
      StageCodePicklist.name = "Advocating - Advanced (90%)"; 
      StageCodePicklist.Value = 200004; 
      opp.Properties["salesstagecode"] = StageCodePicklist; 
     } 
    } 
1

你會想成立實體的SetStateDynamic消息。這不提供目標,所以不是你需要拉EntityMoniker和手動檢索這樣的實體:

  // If this is a setstate call, we need to manually pull the entity 
      if (context.InputParameters.Properties.Contains("EntityMoniker") && 
        context.InputParameters.Properties["EntityMoniker"] is Moniker) 
      { 
       Moniker entity = (Moniker)context.InputParameters.Properties["EntityMoniker"]; 

       // get the entity 
       TargetRetrieveDynamic targetRet = new TargetRetrieveDynamic(); 
       targetRet.EntityId = entity.Id; 
       targetRet.EntityName = context.PrimaryEntityName; 

       RetrieveRequest retrieveReq = new RetrieveRequest(); 
       retrieveReq.ColumnSet = new ColumnSet(); 
       retrieveReq.ColumnSet.AddColumns(new string[]{"opportunityid", "statecode", "statuscode"}); 
       retrieveReq.Target = targetRet; 
       retrieveReq.ReturnDynamicEntities = true; 

       RetrieveResponse retrieveRes = this.Service.Execute(retrieveReq) as RetrieveResponse; 

       // Set the new entity and the status 
       int status = (int)context.InputParameters["Status"]; 
       dynEntity = (DynamicEntity)retrieveRes.BusinessEntity;           
       dynEntity.Properties["statuscode"] = new Status(status);      
      } 
7

我想你會真的想註冊在後段插件SetStateDynamicEntity消息。您不需要此消息的任何過濾屬性。

您的代碼將是這個樣子:

public void Execute(IPluginExecutionContext context) 
{ 
    string state = (string)context.InputParameters["State"]; 
    if (state == "Open") 
    { 
     Moniker entityMoniker = (Moniker)context.InputParameters["EntityMoniker"]; 
     DynamicEntity opp = new DynamicEntity("opportunity"); 
     opp["opportunityid"] = new Key(entityMoniker.Id); 
     opp["salesstagecode"] = new Picklist(/*your value*/); 
     context.CreateCrmService(true).Update(opp); 
    } 
} 
+0

Microsoft建議對SetState和SetStateDynamicEntity消息進行雙重註冊,因爲您無法始終確定哪個消息會被觸發。 – 2010-06-24 14:26:13

相關問題