2013-03-14 79 views
1

我創建了一個插件(使用開發人員工具包),該插件將發送郵件到Participants,該郵件在創建Participants時轉換爲Contacts。 但是這個插件不工作。當我試圖調試它時,下面的消息出現在插件註冊工具(SDK)中爲什麼發送電子郵件插件不工作?

Profiler> Plug-in AppDomain Created 
Profiler> Parsed Profiler File Successfully. 
Profiler> Constructor Execution Started: XXXXXXXX 
Profiler> Constructor Execution Completed Successfully (Duration = 8ms). 
Profiler> Profiler Execution Started: XXXXXXXXXXX 
Plug-in> Entered CRMEmailToParticipantsPackage.EmailPlugins.PostParticipantCreate.Execute(), 
Plug-in> Exiting CRMEmailToParticipantsPackage.EmailPlugins.PostParticipantCreate.Execute(), 
Profiler> Profiler Execution Completed Successfully (Duration = 57ms). 
Profiler> Profiler AppDomain Unloaded 

。管道階段是對創建消息進行預驗證。 這是我的代碼:

protected void ExecutePostParticipantCreate(LocalPluginContext localContext) 
{ 
    if (localContext == null) 
    { 
     throw new ArgumentNullException("localContext"); 
    } 

    // TODO: Implement your custom Plug-in business logic. 

    IPluginExecutionContext context = localContext.PluginExecutionContext; 
    IOrganizationService service = localContext.OrganizationService; 

    if (context.InputParameters.Contains("Target") && 
     context.InputParameters["Target"] is Entity) 
    { 
     try 
     { 
      Entity entity = (Entity)context.InputParameters["Target"]; 
      if (entity.LogicalName == "new_participant") 
      { 
       Guid Contact_id = ((EntityReference)entity.Attributes["new_participantscontact"]).Id; 


       Guid trip_Id = ((EntityReference)entity.Attributes["new_tripparticipants"]).Id; 

       ColumnSet col1 = new ColumnSet("new_name", "new_date", "new_destination"); 
       Entity trip = service.Retrieve("new_trip", trip_Id, col1); 
       var Trip_name = trip.Attributes["new_name"]; 
       var Trip_date = trip.Attributes["new_date"]; 
       var Trip_destination = trip.Attributes["new_destination"]; 
       string emailBody = "Hi, your " + Trip_name.ToString() + "is booked on : " + Trip_date.ToString() + "; Destination : " + Trip_destination.ToString(); 
       Guid _userId = context.UserId; 

       ActivityParty fromParty = new ActivityParty 
       { 
        PartyId = new EntityReference(SystemUser.EntityLogicalName, _userId) 
       }; 


       ActivityParty toParty = new ActivityParty 
       { 
        PartyId = new EntityReference("new_participantscontact", Contact_id) 
       }; 

       Email email = new Email 
        { 
        To = new ActivityParty[] { toParty }, 
        From = new ActivityParty[] { fromParty }, 
        Subject =Trip_name.ToString()+ " :Trip Details", 
        Description = emailBody, 
        DirectionCode = true 
        }; 

       Guid emailID = service.Create(email); 

       SendEmailRequest req = new SendEmailRequest(); 
       req.EmailId = emailID; 
       req.TrackingToken = ""; 
       req.IssueSend = true; 

       SendEmailResponse res = (SendEmailResponse)service.Execute(req); 
      } 
     } 
     catch (FaultException ex) 
     { 

      throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex); 
     } 
    } 
} 

我有沒有做過任何事情錯在這裏?

謝謝。

+0

你怎麼知道插件沒有燒製? – 2013-03-14 09:28:00

+0

Sry它的解僱,我正在使用SDK pluginregistration工具分析這個插件,同時調試什麼都沒有發生 – 2013-03-14 09:40:44

回答

1

我認爲第一件事就是發現你的插件是否被解僱。嘗試debug或使用ITracingService來知道。如果你發現你的插件沒有被解僱,代碼是不必要的。請注意,在CRM Online中部署插件只能在沙盒模式下運行。嘗試在CRM Online中看到這個step-by-step插件的部署。

+0

嗨佩德羅,我編輯了這個問題。 – 2013-03-14 09:51:49

1

您能否使用此處列出的步驟進行調試:http://microsoftcrmworld.blogspot.com/2013/01/debug-plugins-on-your-local-pc-without.html

如果沒有,您可以添加一些localContext.trace()調用,然後在執行方法的最後引發異常。下載並查看日誌文件以查看localContext.trace()的輸出。這會讓你知道發生了什麼。

+0

我的代碼發送郵件是否正確? – 2013-03-15 05:49:58

+0

看起來不錯,電子郵件實體是否已創建但未發送? – 2013-03-15 16:03:54

+0

是的。無論如何知道背後的原因? – 2013-03-16 05:35:43

0

您的代碼似乎很好... 我觀察到您正在向自定義實體發送郵件... 您是否在定製過程中啓用了「發送電子郵件」選項?

Check this link for enabling it

+0

是的,我已啓用該功能。 – 2013-03-16 05:32:29