如何将查找对象值传递给FetchXml查询?

时间:2016-05-04 14:20:02

标签: javascript object dynamics-crm-2015 fetchxml lookupfield

我正在尝试使用另一个查找字段products过滤查找字段editorial(我公司出售教科书)。

我知道如何从查找对象中检索值,但我不知道如何将它们传递到我的fetchXml查询语句中。

function preFilterLookup()
{
    Xrm.Page.getControl("new_editorialsearch").addPreSearch(function () { 

        var ediObject = Xrm.Page.getAttribute("new_editorialsearch").getValue();

        // Get the lookup Object, and extract the Value (ID and Text)
        if(ediObject != null)
        {
            var ediTextValue = ediObject[0].name;
            var ediID = ediObject[0].id;

            // Filter products by editorial
            fetchXml = "<filter type='and'><condition attribute='name' operator='eq' value='" + ediTextValue + "' /></filter>";

            // Apply the filter to the field
            Xrm.Page.getControl("new_engpro").addCustomFilter(fetchXml);
        }        
    });
}

我知道我做错了什么因为CRM一直告诉我我的功能未定义,而且我看不到任何语法错误。

有人可以告诉我将对象名称和id传递给fetchXml语句的正确方法吗?

1 个答案:

答案 0 :(得分:0)

addCustomFilter只能从同一控件的addPreSearch事件中调用。因此,不要在addPreSearch上调用new_editorialsearch,而是在new_engpro上调用它。