Trying to filter results on a related module using /GET filter API

Hope someone con help or point me to some information. We have records in the Knowledge base module and use the /GET filter API to do a realtime search of these solutions on our website.

To give users more targeted results I need to also filter by our related module "Product Class" which is a custom module and related to Knowledge Base use a many to many relationship.

Is it possible to use the filter API to pass the Product Class ID?

I can create this using a custom API calling a custom SQL statement but would like to know if its possible with the filter API. Also is it more efficient to just go with the custom API route.

Below is my current filter payload in JSON

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"filter":[
{
"status":{
"$equals":"published"
},
"$or":[
{
"name":{
"$contains":"driver"
}
},
{
"description":{
"$contains":"driver"
}
}
]
}
],
"max_num":10,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hello  ,

    Thanks for bringing this up!

    Yes, this is definitely possible. For example, if you want to retrieve all Knowledge Base records related to a specific Product Class by its ID, you can use the following request:


    GET: https://{YourSugarURL}/rest/v11_25/PPP_ProductClass/{ProductClassID}/link/ppp_productclass_kbcontents

    In this example:

    The Product Class module is named "PPP_ProductClass".

    The relationship name is "ppp_productclass_kbcontents".

    Let me know if this is what you’re looking for or if you need something more specific!

    Cheers,

    André





  • Hi   thanks for the replay but little confused, can I not add the relationship to the filter JSON?

  • Hello  , 

    In this case, you are not filtering on the target module, do you don't need to add filter information. 

    Since this is a many-to-many relationship, what you actually want to retrieve are all KB_Knowledge records related to a ProductClass record.

    To achieve this, you need to specify the link and the ID of the PPP_ProductClass record.

    I hope this makes sense! You can also refer to this document, which covers a similar scenario:

    Link Fetching Related Records via REST API

    Does this align with what you’re trying to do, or am I missing anything?

    Cheers,

    André

     

  • thanks again, that fine then so filter will only work on fields from the module. I've just created a custom endpoint with my own SQL to do what I need, but thanks for taking the time to answer, good to get the info and the link endpoint