2015-06-30 42 views
-1

如何根據Microsoft Dynamics CRM 2011中插件的條件來防止刪除?我試過InvalidPluginExecutionException但它不工作。防止刪除 - 在CRM 2011中使用插件

這是我的代碼。

try 
{ 
    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) 
    { 
     Entity entity = (Entity)context.InputParameters["Target"]; 
     new_testing testing = entity.ToEntity<new_testing>(); 
     if (testing.new_hutang.Value == true) 
     { 
      throw new InvalidPluginExecutionException("error delete"); 
     } 
    } 
} 
catch (InvalidPluginExecutionException e) 
{ 
    Console.WriteLine("cancel delete plugin" + e); 
} 

你能幫我解決一下需要做什麼嗎?

+1

請提供代碼示例,說明迄今爲止您嘗試過的一些尚未運行的代碼示例,並請澄清您嘗試防止刪除的對象類型。 – bdx

回答

1

您需要將PreImage添加到字段「new_hutang」的插件註冊中。目標實體在默認情況下不會包含刪除的所有字段,但是如果您在註冊插件時指定PreImage實體,則PreImage實體會將其刪除。有關詳細信息,請參閱此博客帖子:https://deepakexploring.wordpress.com/2011/02/04/preentityimages-and-postentityimages-in-crm-5-0-2011/

+0

感謝您的回答。它的工作:) – ahmad

+0

澄清,當你做刪除,目標是一個EntityReference,而不是一個實體,這可能是錯誤。 – Sxntk

0

@Josh Painter(這是最佳方法)的附加內容,您還可以使用JavaScript指令來確保該字段已包含在內。

Xrm.Page.getAttribute("new_hutang").setSubmitMode("always"); 

這條線可能在一個onsave函數中,您可以「附加」到窗體的OnSave事件。這也可以確保該字段存在於您的插件中。