本文介绍了在PREM Dynamics CRM 2016 JavaScript上相当于我的C#QueryExpression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试通过Dynamics CRM获取针对特定查询表达式的FetchXML查询。我已经在C#项目中使用XRM SDK进行了如下操作。I am trying to get the FetchXML query for a specific query expression fro Dynamics CRM. I have manged to do it using the XRM SDK in a C# project as follows. string connectionStr = @"Server=https://mycompany.com/XRMServices/2011/Organization.svc; Username=theUserName; Password=pwd"; Microsoft.Xrm.Client.CrmConnection conn = Microsoft.Xrm.Client.CrmConnection.Parse(connectionStr); var service = new Microsoft.Xrm.Client.CrmOrganizationServiceContext(conn); var query = new QueryExpression(); QueryExpressionToFetchXmlRequest req = new QueryExpressionToFetchXmlRequest(); query.EntityName = "my_entity"; query.ColumnSet = new ColumnSet("_accountnumber", "_id"); FilterExpression filter = new FilterExpression(); filter.Conditions.Add(new ConditionExpression("_Oactivedate", ConditionOperator.NotNull)); filter.Conditions.Add(new ConditionExpression("_Oinactivedate", ConditionOperator.Null)); filter.Conditions.Add(new ConditionExpression("_state", ConditionOperator.Equal, 0)); FilterExpression filter1 = new FilterExpression(LogicalOperator.Or); var filter2 = new FilterExpression(LogicalOperator.And); filter2.Conditions.Add(new ConditionExpression("_lastname", ConditionOperator.Equal, lastName)); filter2.Conditions.Add(new ConditionExpression("_accountnumber", ConditionOperator.Equal, accountId)); var filter3 = new FilterExpression(LogicalOperator.And); filter3.Conditions.Add(new ConditionExpression("_accountactivedate", ConditionOperator.NotNull)); filter3.Conditions.Add(new ConditionExpression("_accountinactivedate", ConditionOperator.Null)); filter1.AddFilter(filter2); filter1.AddFilter(filter3); filter.AddFilter(filter1); query.Criteria = filter; req.Query = query; QueryExpressionToFetchXmlResponse resp = (QueryExpressionToFetchXmlResponse)service.Execute(req); //fetchxml string string myfetch = resp.FetchXml;我的要求不允许使用.Net DLL,因此我想在JS中执行此操作。我尝试查看JS SDK,它不如C#友好(也许只是我:)。我真的很感激任何可以尝试编写与我上面的代码等效的JS的人,或者提供了可以帮助我自己理解的优秀材料指南。我的主要兴趣是从动态强类型QueryExpression对象生成FetchXml查询。谢谢!My requirement doesn't allow for a .Net DLL, therefore I would like to do this in JS. I have tried to look at the JS SDK and it is not as friendly as the C# one (maybe it's just me :). I would really appreciate anyone who can attempt to write a JS equivalent of my code above, or guide to a good material that can help me figure it out myself. My main interest is the generation of the FetchXml query from a dynamic strongly typed QueryExpression object. Thanks!推荐答案您应该能够在高级查找和从那里下载fetchxml以在JavaScript中使用。 了解详情You should be able to build your query in Advanced find & Download the fetchxml from there to use in JavaScript. Read more您可以使用 XrmToolBox-FetchXml Builder 以及用于构建查询(这也会提供与SQL,QueryExpression等效的查询),然后使用此在线格式化工具You can use XrmToolBox - FetchXml Builder as well for building queries (this will give SQL, QueryExpression equivalent too), then generate language compatible output using this online formatter tool在JavaScript中使用fetchxml的代码示例可以在此博客。例如:Code sample to use fetchxml in JavaScript can be find in this blog. For Example:var encodedFetchXml = encodeURI(fetchContact);var reqURL = clientURL + "/api/data/v8.2/contacts?fetchXml=" + encodedFetchXml;var req = new XMLHttpRequest();req.open("GET", reqURL, false); QueryExpression,FetchXml,LINQ都是编写同一查询的选择。如您所知-QueryExpression不能在JavaScript中使用,但fetchxml可以在C#& JS。QueryExpression, FetchXml, LINQ are all choices to write the same query. As you know - QueryExpression cannot be used in JavaScript, but fetchxml can be used in both C# & JS. 这篇关于在PREM Dynamics CRM 2016 JavaScript上相当于我的C#QueryExpression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-13 09:53