【问题标题】:Dynamics CRM 2011 retrieve all subjectsDynamics CRM 2011 检索所有主题
【发布时间】:2012-10-08 19:33:48
【问题描述】:

我目前正在学习 CRM 2011,同时使用它,我认为这可能是一个有用的示例。 在 javascript 函数中,我需要检索所有主题实体记录并将它们缓存在客户端上。 我还需要将它们缓存在它们的层次结构中。 我认为最好的方法是返回每个主题记录及其 id 和父 id,这样我就可以在 javascript 中构建客户端结构。

有 CRM 经验的人对如何编码这个查询有任何建议吗?我可以处理数据,只是不知道如何返回我需要的结果!

谢谢

【问题讨论】:

    标签: javascript dynamics-crm-2011


    【解决方案1】:

    我发现使用 OData 服务是在客户端 javascript:CRM 2011, Getting started with OData 中返回所需信息的最佳方式。

    【讨论】:

    • 通过对 $select 和 $expand 语法的一些研究,您可以根据需要返回关系。
    【解决方案2】:

    您的回答可能有效,但我的点击次数过多。

    这就是我最后的做法。 cacheSubjects 是主要功能:

    var sgc_subjectCache = [];
    var sgc_subjectCacheCount = 0;
    
    function cacheSubjectsCallback(data) {
        // update subjects
        // loop through retrieved subjects and add to cache
        for( i=0; i < data.length; i++ )
        {
            var subject = data[i];
            subject.Root = subject.Title;
            // var subjectid = subject.SubjectId;
            sgc_subjectCache.push( subject );
            sgc_subjectCacheCount += 1;
        }
    }    
    
    function cacheSubjectsComplete() {
        // now update title with ancestors
        var done = false;
        while(done==false)
        {
            done = true;
            // outer loop
            var len = sgc_subjectCache.length;
            for( var i=0; i < len-1; i++ )
            {
                subject = sgc_subjectCache[ i ];
                // inner loop
                for( var j=0; j < len-1; j++ )
                {
                    subject2 = sgc_subjectCache[ j ];
                    if( subject.ParentSubject.Id === subject2.SubjectId )
                    {
                        // found the parent
                        var newTitle = subject2.Title + ' : ' + subject.Title;
                        sgc_subjectCache[ i ].Title = newTitle;
                        sgc_subjectCache[ i ].Root = subject2.Root;
                        sgc_subjectCache[ i ].ParentSubject.Id = subject2.ParentSubject.Id;
                        done = false; // more to do
                    }
                }
            }
        }
    
    }
    
    function cacheSubjects() {
        sgc_subjectCache = [];
        var options = "$select=Title,SubjectId,ParentSubject";
        SDK.REST.retrieveMultipleRecords("Subject", options, cacheSubjectsCallback, function(error) {
            alert( error );
        }, cacheSubjectsComplete);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多