简体   繁体   English

Acumatica REST API - 从 Contact/ContactUserInfo 获取角色数组

[英]Acumatica REST API - Get Roles Array from Contact/ContactUserInfo

I'm attempting to GET a list of contacts who are assigned to a specific role.我正在尝试获取分配给特定角色的联系人列表。 If my contact has the user role "Sales Rep", then I'd want to get all Contacts for whom "Sales Rep" is among their roles.如果我的联系人具有用户角色“销售代表”,那么我想要获取所有“销售代表”在其角色中的联系人。

For context, the Contact Model looks like this:对于上下文,Contact Model 如下所示:

{
   id: "7e87d8fc-6d18-4g95-8334-e54b69e2803t",
   ... // additional fields

   UserInfo: { // <-- ContactUserInfo entity
       id: "da1b408e-571c-4896-be61-a02c5f99b1ec",
       ... // additional fields,
       Roles: [] // <-- Roles are stored here as ContactRole entities
   }
} 

Screenshot of Contact Model in API Docs API 文档中的联系人 Model 截图

What I've tried so far:到目前为止我已经尝试过:

  1. According to the Integration Development Guide (pg 65) , linked and detail entities have to be explicitly specified in the expand parameter, so that gives me the following:根据集成开发指南(第 65 页) ,必须在 expand 参数中明确指定链接实体和详细实体,这样就可以得到以下信息:

    {{site}}/entity/Default/18.200.001/Contact?$expand=UserInfo/Roles

    However, this gives me the error:但是,这给了我错误:

    Optimization cannot be performed.The following fields cause the error: UserInfo.Roles.RoleDescription: View Roles has BQL delegate.


  1. So I looked into this BQL Delegate issue.所以我调查了这个 BQL 代表问题。 According to the Acumatica wiki (scroll to the bottom, "Usage Notes for Endpoints with Contract Version 3"), there are two solutions to this:根据Acumatica wiki (滚动到底部,“使用合同版本 3 的端点的使用说明”),对此有两种解决方案:

    2a. 2a。 Don't use those fields ( not an option )不要使用这些字段(不是选项

    2b. 2b。 Retrieve the problematic fields one by one.逐一检索有问题的字段。 BUT I can't do this because neither the ContactUserInfo or ContactRole endpoints are top level entities, meaning I can't make an HTTP request to those endpoints even if I have their id's,但是我不能这样做,因为 ContactUserInfo 或 ContactRole 端点都不是顶级实体,这意味着即使我有它们的 id,我也无法向这些端点发出 HTTP 请求,


  1. So I thought maybe I can link the Roles array to the Contact entity instead of the ContactUserInfo entity.所以我想也许我可以将 Roles 数组链接到 Contact 实体而不是 ContactUserInfo 实体。 I followed the steps outlined here under "To Add a Linked or Detail Entity to Another Entity" but when I get to step 4, my "Insert" button is disabled, preventing me from proceeding.我按照“将链接或详细信息实体添加到另一个实体”概述的步骤操作,但是当我进入第 4 步时,我的“插入”按钮被禁用,阻止我继续。

  1. I saw a thread somewhere that indicated that perhaps if I fetched the Contacts one by one instead of as a list, the optimization process would be easier and the Roles array would be visible.我在某处看到一个线程,表明如果我一个一个地获取联系人而不是列表,优化过程会更容易,并且角色数组将可见。 So I snagged a Contact Id and modified my request to get one Contact instead of a list:所以我抓住了一个联系人 ID 并修改了我的请求以获取一个联系人而不是列表:

    {{site}}/entity/Default/18.200.001/Contact/7e87d8fc-6d18-4g95-8334-e54b69e2803t?$expand=UserInfo

    but now, for some reason, UserInfo 's value is null .但是现在,由于某种原因, UserInfo的值是null The rest of the fields are the same as when this Contact was in a list, so it's definitely getting the correct data, but now the UserInfo field is null?字段的 rest 与此联系人在列表中时相同,因此肯定得到正确的数据,但现在 UserInfo 字段是 null?

Thank you谢谢

Hopefully one of my attempts was on the right track.希望我的尝试之一是在正确的轨道上。 Happy to provide any additional details upon request.很高兴根据要求提供任何其他详细信息。

If you need to get specific data that is unavailable in the screen, like the issue you are having, you can build a Generic Inquiry in Acumatica and expose it through web services.如果您需要获取屏幕中不可用的特定数据,例如您遇到的问题,您可以在 Acumatica 中构建一个通用查询并通过 web 服务公开它。

I was able to build a GI joining PX.Objects.CR.Contact, PX.SM.Users, and PX.SM.UsersInRoles and then filtering by the RoleName being equal to Sales Reps (if you check from schema, you can browse to the role).我能够构建一个连接 PX.Objects.CR.Contact、PX.SM.Users 和 PX.SM.UsersInRoles 的 GI,然后按等于 Sales Reps 的 RoleName 进行过滤(如果您从架构中检查,您可以浏览到角色)。 Next, add all of the columns you want to the GI that you want on your web service.接下来,将所需的所有列添加到 web 服务上所需的 GI。 Ensure you check the box Visible in the UI on the Generic Inquiry, and test your data through visiting the created GI.确保您在通用查询中选中 UI 中的可见框,并通过访问创建的 GI 来测试您的数据。

From there, you can follow Diane Cawley's blog on how to expose the GI through web services.从那里,您可以关注 Diane Cawley 的博客,了解如何通过 web 服务公开 GI。

https://www.acumatica.com/blog/contract-based-apis-in-generic-inquiries/ https://www.acumatica.com/blog/contract-based-apis-in-generic-inquiries/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM