最近很多朋友(Andrew、BENEN1)都在问如何让Lookup显示InActive记录,研究后发现可以通过Plugin来实现这样的功能,
MSCRM真是无所不能,没有做不到,只有想不到!
实现步骤:
一、自定义实体->工程项目->表单和视图->查找视图->添加查找列 选择创建者 确保创建者属性在最后一列,如下图:
二、Plugin开发
代码:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
namespace PluginDemo
{
public class QuoteLookupShowAllRecord : IPlugin
{
#region IPlugin 成员
public void Execute(IPluginExecutionContext context)
{
if (context.InputParameters.Contains("FetchXml"))
{
string FetchXml = (String)context.InputParameters["FetchXml"];
if (FetchXml.Contains("<entity name=\"new_project\">"))
{
if (FetchXml.Contains("<attribute name=\"createdby\" /><filter type=\"and\"><condition attribute=\"statecode\" operator=\"eq\" value=\"0\" /></filter>"))
{
context.InputParameters["FetchXml"] = FetchXml.Replace("<attribute name=\"createdby\" /><filter type=\"and\"><condition attribute=\"statecode\" operator=\"eq\" value=\"0\" /></filter>", "<attribute name=\"createdby\" /><filter type=\"and\"></filter>");
}
}
}
}
#endregion
}
}
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
namespace PluginDemo
{
public class QuoteLookupShowAllRecord : IPlugin
{
#region IPlugin 成员
public void Execute(IPluginExecutionContext context)
{
if (context.InputParameters.Contains("FetchXml"))
{
string FetchXml = (String)context.InputParameters["FetchXml"];
if (FetchXml.Contains("<entity name=\"new_project\">"))
{
if (FetchXml.Contains("<attribute name=\"createdby\" /><filter type=\"and\"><condition attribute=\"statecode\" operator=\"eq\" value=\"0\" /></filter>"))
{
context.InputParameters["FetchXml"] = FetchXml.Replace("<attribute name=\"createdby\" /><filter type=\"and\"><condition attribute=\"statecode\" operator=\"eq\" value=\"0\" /></filter>", "<attribute name=\"createdby\" /><filter type=\"and\"></filter>");
}
}
}
}
#endregion
}
}
注册Plugin: