none
lookupMulti的筛选问题:主要实现的功能是:对账清单===退货单(1--N关系),选择"对账清单"中的”退货单“,点击“添加已有退货单”,弹出lookupmulti,将对账清单的id传给lookupmulti,根据ID筛选 RRS feed

  • 问题

  • 我看了jimwang的博客http://mscrm.cnblogs.com/,写了一下,但他写的是n==n的关系,我写的是1=n的关系,代码如下:
    jimwang所写的第一部分的pulgin,我已经写好了,代码为js调用部分。贴出来,刀客,jim以及各位高手请教问题改如何解决:
    不在修改实体关系的前提下,能否将问题解决!
    //1部分
    
    var lookupEntityTypeCode;
    
    var lookupEntityTypeCode1;
    
    var lookupId;
    
    var loadAreaId;
    
    var loadAreanew;
    
    
    
    
    
    function lookupFilter_FH(loadAreaId1,loadAreaId2,buttonTitles,buttonTitles1,lookupId1,displaycode,displaycode1)
    
    {
    
    lookupId=lookupId1;
    
    loadAreaId=loadAreaId1;
    
    loadAreanew=loadAreaId2;
    
     var navElement = document.getElementById('nav_' + loadAreaId);
    
     var navElement1 = document.getElementById('nav_' + loadAreanew);
    
        if (navElement != null) {
    
            navElement.onclick = function LoadAreaOverride() {
    
                // Call the original CRM method to launch the navigation link and create area iFrame
    
                loadArea(loadAreaId);
    
             
    
                var Iframe=document.getElementById(loadAreaId + 'Frame');
    
                         if (Iframe != null) {
    
                    Iframe.onreadystatechange = function HideTitledButtons() {
    
                        if (Iframe.readyState == 'complete') {
    
                            var iFrame = frames[window.event.srcElement.id]; 
    
                            var liElements = iFrame.document.getElementsByTagName('li'); 
    
                            for (var j = 0; j < buttonTitles.length; j++) {
    
                                for (var i = 0; i < liElements.length; i++) {
    
                                         var action = liElements[i].getAttribute("action");
    
    
    
                                         if(liElements[i].getAttribute('title') == displaycode )
    
                                          {
    
                                             liElements[i].style.display = 'none';
    
                                          }
    
                                       if(action != null && action.indexOf(loadAreaId) > 1 && liElements[i].getAttribute('title') == buttonTitles[j] )
    
                                       {
    
                                          
    
                                            lookupEntityTypeCode = action.substring(action.indexOf("\(")+1, action.indexOf(","));
    
                                             liElements[i].onclick = function CustomLookup()
    
                                            {
    
                                              
    
                                                var lookupSrc = "/" + ORG_UNIQUE_NAME + "/_controls/lookup/lookupmulti.aspx?class=&objecttypes=" + lookupEntityTypeCode + "&browse=0";
    
                                               
    
                                                if(lookupId != null)
    
                                                {
    
                                                    lookupSrc = lookupSrc + "&id=" + lookupId;
    
                                                }
    
                                                var lookupItems= window.showModalDialog(lookupSrc,"dialogWidth:850px;DialogHeight:600px;status:no;scroll=0");
    
                                                if (lookupItems)
    
                                                {
    
                                                    if ( lookupItems.items.length > 0 )
    
                                                    {
    
                                                        alert('c');
    
                                                       
    
                                                        //AssociateObjects( crmFormSubmit.crmFormSubmitObjectType.value, crmFormSubmit.crmFormSubmitId.value, lookupEntityTypeCode, lookupItems, true, null, loadAreanew); 
    
                                                
    
                                                         // This is the CRM internal JS funciton on \_static\_grid\action.js
    
                                                    }
    
                                                }
    
                                            }
    
                                            
    
                                            return;
    
                                           
    
                                      }
    
                                     
    
                                    }
    
                                }
    
                            }
    
                        }
    
                    }
    
                }
    
            }
    
           if (navElement1 != null) {
    
            navElement1.onclick = function LoadAreaOverride() {
    
                // Call the original CRM method to launch the navigation link and create area iFrame
    
            
    
                loadArea(loadAreanew);
    
                var Iframe1=document.getElementById(loadAreanew + 'Frame');
    
                         if (Iframe1 != null) {
    
                    Iframe1.onreadystatechange = function HideTitledButtons() {
    
                        if (Iframe1.readyState == 'complete') {
    
                            var iFrame1 = frames[window.event.srcElement.id]; 
    
                            var liElements1 = iFrame1.document.getElementsByTagName('li'); 
    
                            for (var m = 0; m < buttonTitles1.length; m++) {
    
                                for (var n = 0; n < liElements1.length; n++) {
    
                                         var action1 = liElements1[n].getAttribute("action");
    
                                         if( liElements1[n].getAttribute('title') == displaycode1)
    
                                          {
    
                                             liElements1[n].style.display = 'none';
    
                                          }
    
                                       if(action1 != null && action1.indexOf(loadAreanew) > 1 && liElements1[n].getAttribute('title') == buttonTitles1[m] )
    
                                       {
    
                                          
    
                                            lookupEntityTypeCode1 = action1.substring(action1.indexOf("\(")+1, action1.indexOf(","));
    
                                            liElements1[n].onclick = function CustomLookup1()
    
                                        {
    
                                          
    
                                            var lookupSrc1 = "/" + ORG_UNIQUE_NAME + "/_controls/lookup/lookupmulti.aspx?class=&objecttypes=" + lookupEntityTypeCode1 + "&browse=0";
    
                                           
    
                                            if(lookupId != null)
    
                                            {
    
                                                lookupSrc1 = lookupSrc1 + "&id=" + lookupId;
    
                                            }
    
                                            var lookupItems1= window.showModalDialog(lookupSrc1,"dialogWidth:850px;DialogHeight:600px;status:no;scroll=0");
    
                                            if (lookupItems1)
    
                                            {
    
                                                if ( lookupItems1.items.length > 0 )
    
                                                {
    
                                                    alert('c');
    
                                                    
    
                                                    //AssociateObjects( crmFormSubmit.crmFormSubmitObjectType.value, crmFormSubmit.crmFormSubmitId.value, lookupEntityTypeCode, lookupItems, true, null, loadAreanew); 
    
                                                   
    
                                                     // This is the CRM internal JS funciton on \_static\_grid\action.js
    
                                                }
    
                                            }
    
                                        }
    
                                            
    
                                            return;
    
                                           
    
                                      }
    
                                     
    
                                    }
    
                                }
    
                            }
    
                        }
    
                    }
    
                }
    
            }
    
            
    
        }
    
    
    调用部分的js写在了onload()事件中,
    1部分的js写在了CRMWeb\_static\_controls\RemoteCommands\RemoteCommand.js中。
    问题的点在:AssociateObjects( crmFormSubmit.crmFormSubmitObjectType.value, crmFormSubmit.crmFormSubmitId.value, lookupEntityTypeCode, lookupItems, true, null, loadAreanew);中的loadAreanew,
    韩兄,你做的是n==n的关系,我写的是1==n的关系,


    //调用
    
    var relId = "ol_statement_shippinglist";
    
    var lookupId = crmForm.ObjectId;  
    
    var displayCode="添加新发货单到此记录表";
    
    var relId1= "ol_statement_backgoods";
    
    var displayCode1="添加新退货单到此记录表";
    
    if(lookupId!=null)
    
    {
    
    lookupFilter_FH(relId,relId1,['将现有发货单添加到此记录'],['将现有退货单添加到此记录'],lookupId,displayCode,displayCode1);
    
    
    
    }
    
    
    具体报错:
    pulgin部分我调试,没有问题,点击“添加现有的退货单”中的”确定“按钮,报出一下的错,请韩兄和jim给出解决方案,小弟先谢谢了

    1:Crm Exception: Message: Entity Relationship ol_statement_backgoods is not a many-to-many entity relationship, ErrorCode: -2147220918
    
    2:MessageProcessor fail to process message 'AssociateEntities' for 'none'.
    
    3:at ErrorInformation.LogError()
    
    at ErrorInformation..ctor(Exception exception, Uri requestUrl, Boolean logError)
    
    at ErrorInformation..ctor(Exception exception, Uri requestUrl)
    
    at AppWebService.CreateSoapException(Exception innerException)
    
    at AssociateRecords.Associate(Int32 objectType, Int32 parentObjectType, Guid objectId, Guid parentId, String subType, String associationName)
    
    at RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    
    at RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    
    at RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    
    at RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    
    at LogicalMethodInfo.Invoke(Object target, Object[] values)
    
    at WebServiceHandler.Invoke()
    
    at WebServiceHandler.CoreProcessRequest()
    
    at SyncSessionlessHandler.ProcessRequest(HttpContext context)
    
    at CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    
    at HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    
    at ApplicationStepManager.ResumeSteps(Exception error)
    
    at HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
    
    at HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
    
    at HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)
    
    at ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType)
    
    >MSCRM Error Report:
    
    --------------------------------------------------------------------------------------------------------
    
    Error: 调用的目标发生了异常。
    
    Error Number: 0x8004024A
    
    Error Message: Entity Relationship ol_statement_backgoods is not a many-to-many entity relationship
    
    Error Details: Entity Relationship ol_statement_backgoods is not a many-to-many entity relationship
    
    Source File: Not available
    
    Line Number: Not available
    
    Request URL: http://192.168.1.51:5555/OrientLaser/AppWebServices/AssociateRecords.asmx
    
    Stack Trace Info: [CrmException: Entity Relationship ol_statement_backgoods is not a many-to-many entity relationship]
    
    在 Microsoft.Crm.BusinessEntities.BusinessProcessObject.GetAssociationEntityRelationship(String associationRelationshipName, ExecutionContext context)
    
    在 Microsoft.Crm.BusinessEntities.BusinessProcessObject.HandleAssociationOperation(BusinessEntityMoniker entityOneMoniker, BusinessEntityMoniker entityTwoMoniker, String associationRelationshipName, Boolean createAssociation, ExecutionContext context)
    
    在 Microsoft.Crm.BusinessEntities.BusinessProcessObject.AssociateEntities(BusinessEntityMoniker entityOneMoniker, BusinessEntityMoniker entityTwoMoniker, String associationRelationshipName, ExecutionContext context)
    
    [TargetInvocationException: 调用的目标发生了异常。]
    
    在 System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    
    在 System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    
    在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    
    在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    
    在 System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)
    
    在 Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IPluginExecutionContext context)
    
    在 Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext context)
    
    在 Microsoft.Crm.Extensibility.Pipeline.Execute(PipelineExecutionContext context)
    
    在 Microsoft.Crm.Extensibility.MessageProcessor.Execute(PipelineExecutionContext context)
    
    在 Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(PipelineExecutionContext context)
    
    在 Microsoft.Crm.Extensibility.ExternalMessageDispatcher.Execute(String messageName, Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, PropertyBag fields, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
    
    在 Microsoft.Crm.Sdk.RequestBase.Process(Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
    
    在 Microsoft.Crm.Sdk.RequestBase.Process(CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
    
    在 Microsoft.Crm.Sdk.CrmServiceInternal.Execute(RequestBase request, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
    
    在 Microsoft.Crm.Sdk.InProcessCrmService.Execute(Object request)
    
    在 Microsoft.Crm.Application.Platform.ServiceCommands.PlatformCommand.ExecuteInternal()
    
    在 Microsoft.Crm.Application.Platform.ServiceCommands.AssociateEntitiesCommand.Execute()
    
    在 Microsoft.Crm.Application.WebServices.AssociateRecords.Associate(Int32 objectType, Int32 parentObjectType, Guid objectId, Guid parentId, String subType, String associationName)
    2009年9月11日 6:28

答案

全部回复

  • AssociateObjects专用于N:N;
    1:N的实现不一样的,需要重新考虑。

    Jim Wang - MVP Dynamics CRM - http://jianwang.blogspot.com, http://mscrm.cn
    2009年9月12日 9:02
    版主
  • 谢谢你的回答,如果在不改变实体关系的基础上有没有更好的解决方法?
    请jim wang继续关注!
    2009年9月14日 6:29
  • 其实过滤LookupSingle已有解决方案,你看看这三篇Blog能否解决你的问题:


    神秘的 CRM Lookup (I)
    神秘的 CRM Lookup (II)
    神秘的 CRM Lookup (III)

    Cheers,
    Jim


    Jim Wang - MVP Dynamics CRM - http://jianwang.blogspot.com, http://mscrm.cn
    2009年9月14日 7:34
    版主
  • 恩,我先理解你写的以上三篇文章,然后在针对我的问题在想方法,谢谢jim的回答
    2009年9月14日 7:40
  • jim wang ,我看了你推荐的三篇文章,我发现仍然无法解决我的问题,我的需求是这样的  对账清单(ol_statement)和发货单(ol_shipping)是1==n的关系,在对账清单中的发货单,点击“现有发货单”,1.过滤掉发货单中对账清单为空的记录。2.点击”确定“对选择的多条记录进行条件判断是否满足条件,满足条件让它可以添加。现在是1,无法过滤,2 可以先暂缓实现。请jim wang 解答。还想请问,  mscrm4.0中n==n关系机制是如何的,是不是a与b实体是n==n关系,mscrm会自动建一个中间表c ,  a与c是n---1,b与c也是n--1的关系。不是很明白n===n的关系是如何创建的?
    2009年9月17日 8:11
  • jim wang,上面提到的过滤问题,我已经找到了其他的解决方案,我不在lookupMulti中实现过滤了,山重水复疑无路,柳暗花明又一村,谢谢jim wang的关注。
    2009年9月18日 3:31