微软crm mscrm 区域城市联动 用js+plugin实现

===onload======

var lookupItem = new Array;
lookupItem = crmForm.all.new_regionid.DataValue;
if (lookupItem != null)
{
    crmForm.all.new_regioncityid.additionalparams =  'id='+lookupItem[0].id;
}
else
{
    crmForm.all.new_regioncityid.additionalparams =  'id={00000000-0000-0000-0000-000000000001}';
}

=======regionid   onchange========

var lookupItem = new Array;
lookupItem = crmForm.all.new_regionid.DataValue;
if (lookupItem != null)
{
    crmForm.all.new_regioncityid.additionalparams =  'id='+lookupItem[0].id;
}
else
{
    crmForm.all.new_regioncityid.additionalparams =  'id={00000000-0000-0000-0000-000000000001}';
}

crmForm.all.new_regioncityid.DataValue=null;

 =======将下面代码做成Plug-In,并用注册工具注册到 execute 的message========

 public class PILookupFilter : IPlugin
    {
        #region IPlugin 成员

        public void Execute(IPluginExecutionContext context)
        {
            if (context.InputParameters.Contains("FetchXml"))
            {
                string FetchXml = (String)context.InputParameters["FetchXml"];
                string guid = HttpContext.Current.Request.QueryString["id"] == null ? null : HttpContext.Current.Request.QueryString["id"].ToString();

                //throw new InvalidPluginExecutionException(FetchXml);

                #region 根据区域Guid显示相应的区域城市
                if (guid != null && FetchXml.Contains("<entity name=\"new_regioncity\">"))
                {
                    if (new Guid(guid).Equals(new Guid()) == false)
                    {
                        string oldChar = "</entity>";
                        string newChar = "<link-entity name=\"new_region\" from=\"new_regionid\" to=\"new_regionid\" alias=\"aa\"><filter type=\"and\"><condition attribute=\"new_regionid\" operator=\"eq\" uitype=\"new_region\" value=\"" + guid + "\"/></filter></link-entity></entity>";

                        //throw new InvalidPluginExecutionException(FetchXml.Replace(oldChar, newChar));

                        context.InputParameters["FetchXml"] = FetchXml.Replace(oldChar, newChar);
                    }
                }
                #endregion                         
        }

        #endregion

}

原文地址:https://www.cnblogs.com/seerlin/p/1869102.html