如何通过ID以外的任何方式获取记录-SugarCRM [英] How to get a record by anything else than it's id - SugarCRM

查看:106
本文介绍了如何通过ID以外的任何方式获取记录-SugarCRM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可能不清楚这个问题,但是我的问题很简单

The question might be unclear to you but my problem is very simple

SugarCRM文档建议要获取记录,我应该向/<module>/:recordId发送GET请求.

The SugarCRM documentation suggests that to get a record, I should send a GET request to /<module>/:recordId.

我想要实现的是通过电子邮件获取记录.

What I want to achieve is to get a record by its email.

在先前版本的SugarCRM中,我可以在有效负载请求中向其API发送一个SQL查询. 但是这里是GET请求,所以没有正文.

In previous version of SugarCRM, I could send an SQL query to their API in the payload request. But here since it is a GET request there is no body.

我需要帮助

推荐答案

要通过匹配非id字段获取记录,可以使用记录过滤器API /<module>/filter(请参阅

To get records by matching non-id fields you can use the record filter API /<module>/filter (see documentation or /rest/v10/help of your Sugar) to specify which field(s) to search for what values.

如果最多只关心一条匹配的记录,请在选项中指定"max_num": 1.

If you only care for one matching record at most, specify "max_num": 1 in the options.

作为响应,您将收到一个带有records数组的json对象,其中包含匹配的记录.

As response you will receive a json object with a records array containing the matching record(s).

按电子邮件地址过滤

电子邮件地址以前存储在字段email1,email2等中. 这些旧字段仍然存在于Sugar> = 7中(目前),并且可以与这样的请求有效负载一起使用:

Email addresses were previously stored in fields email1, email2, etc. Those legacy fields do still exist in Sugar >=7 (for now) and could be used with a request payload like this:

{
    max_num: 1,
    filter: [
        {"email2": "test@secondary.test"},
    ],
    fields: ["id"],
}

这将仅在辅助电子邮件地址中搜索电子邮件地址.

This will search for the email address in only the secondary email-address.

但是,在现代的Sugar中,电子邮件地址存储在名为email_addresses的关系支持的链接字段中,该字段连接到EmailAddress记录,可以通过以下方式进行搜索:

However, in modern Sugar, email addresses are stored in a relationship-backed link field called email_addresses that connects to EmailAddress records which can be searched like these:

{
    max_num: 1,
    filter: [
        {"email_addresses.email_address": {"$equals": "test@something.test"}},
    ],
    fields: ["id"],
}

这将返回与 any 电子邮件地址匹配的记录.不管是主要的还是另一种.

This will return an record with any email address matching. Regardless of whether it's the primary one or another one.

随机注释

  • 过滤器端点显然支持GETPOST方法,因此您可以选择是通过请求的查询字符串还是在请求正文中传输过滤器定义和选项.
  • /<module>端点的
  • GET请求将使用相同的基础过滤器API.但是,您不能在/<module>上使用POST进行过滤,因为该组合保留用于创建新记录.
  • 如果您不确定Sugar过滤器语法中的搜索条件应该是什么样子,则可以使用Sugar在模块列表视图中创建示例过滤器,并在浏览器的调试器的网络"标签中检查Sugar产生的请求有效载荷是什么看起来像.
  • 如果您需要通配符搜索,则可以使用通配符%来实现,例如对于%@whatever.test,似乎需要使用与$equals不同的运算符,例如$starts$contains.
  • 如果您只关心匹配数而不是实际记录,则将过滤器发送到/<module>/count(GET)端点或/<module>/filter/count(GETPOST).
  • 在开发测试期间,我建议使用max_num高于预期的返回值,以确保如果由于错误的过滤器定义而导致结果出现误报,请立​​即查看.还是要特别注意响应json中的next_offset:如果没有比响应中已经返回的结果多的结果,它将具有值-1.
  • $equals运算符有一个简短的表示法,例如{"email_addresses.email_address": {"$equals": "test@something.test"}},也可以写为{"email_addresses.email_address": "test@something.test"},.
  • The filter endpoint apparently supports both the GET and the POST method, so you can choose whether to transfer the filter definition and options via the request's query string or in the request body.
  • GET requests to the /<module> endpoint will use the same underlying filter API. However you cannot filter using POST on /<module>, because that combination is reserved for creating new records.
  • If you are unsure about what your search criterias should look like in Sugar filter syntax, you might be able to use Sugar to create an example filter in the modules list view and check in the browser's debugger's network tab what Sugar's resulting request payload looked like.
  • If you need a wildcard search, you can accomplish that by using the wildcard character %, e.g. for %@whatever.test, seems to require using a different operator than $equals though, e.g. $starts or $contains.
  • If you only care about the number of matches, not the actual records, send your filter to the /<module>/count (GET) endpoint or to /<module>/filter/count (GET or POST).
  • During development testing I recommend using a max_num higher than what you expect to be returned, to make sure you see it immediatly if you get any false positives in your results due to an incorrect filter definition. That or pay close attention to next_offset in the response json: It will have the value -1 if there are no more results than those already returned in the response.
  • There is a short notation for the $equals operator, e.g. {"email_addresses.email_address": {"$equals": "test@something.test"}}, could also be written as {"email_addresses.email_address": "test@something.test"},.

这篇关于如何通过ID以外的任何方式获取记录-SugarCRM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆