SugarCRM $in filter

I’m attempting to search for Notes within SugarCRM using an “$in” filter (front end label is “Finds anything where field matches one of the values as specified as an array”).

It states that it needs an array passed to it for the value (which makes total sense) but I cannot seem to get this to work.

I’ve tried a flat array of ids [id1,id2,id3] etc but to no avail.

Can someone from Make please let me know what it expects the array to look like?

Incidentally I have also tried mapping it instead and just setting up the filter syntax as a string but it then complains and says it should be an array :confused:

Any and all help much appreciated.

In order for us in the community to be able to assist with your question, we would need to get more information like:

  • What are you trying to achieve with the scenario? (eventual goal)
  • What steps have you taken so far to resolve your issue?

Also, please take a camera-viewfinder-duotone screenshot of your scenario along with the relevant module configurations and share-all-duotoneshare the images here so that the community has a deeper understanding of how we could help.

Hi @Bjorn.drivn

The eventual goal isn’t particularly relevant to this specific issue, but let’s say it’s to return a list of Notes from Sugar for processing.

I’ll add screen shots when I’m back in the office tomorrow but if you want to test it out all you have to do is set up a new scenario, add a stand alone SugarCRM Search element for any module (connected to a Sugar instance obviously), set the filter item 1 as below…

  • Field Name: id
  • Operation Types: Finds anything where field matches one of the values as specified as an array ($in)
  • Field Value: ​add(​emptyarray​;<Your Id(s) Here>)​

Make then throws an error stating [422] $in requires an array.

As far as I can see I’m giving it an array :confused:

It would just be useful to know exactly what Make is expecting in that field.

Cheers

1 Like

Hi @Simon_Langham ,

As @Bjorn.drivn said, please add some screenshots.

If you want to transform a string like “[id1,id2,id3]” to an array, you can use this function:
image
The corresponding blueprint:
string to array.json (4.0 KB)

Hope it helps.

Philippe

2 Likes

@Philippe_Billet I prefer to avoid string manipulation where possible, especially if there are methods designed to be used with arrays such as add which can be utilised to do the same thing. I have a good level of experience with coding just for some background info so am happy with the concept of data types etc :+1:

I have however employed your method in the screen shots to show it appears to be nothing to do with the array being passed in.

thumb-Screenshot at 2023-11-15 09-21-11

As you can see this should be passing an array to the method however the result is below…

thumb-Screenshot at 2023-11-15 09-22-20

If you pass anything other than an array to this component it breaks with a make.com error saying it expects an array of objects etc.

The error above is being passed back from Sugar by the looks of things, so I think it’s something make is doing to the array before passing it across.

Any other ideas guys?

Sorry to bother you, but the screenshots are small, they are almost unreadable after zooming.

Could you, please, change your screenshots?

PBI

@Philippe_Billet yeah I just realised that myself sorry - will get a colleague to do it instead, my linux machine is clearly having a mare :slight_smile:

@Philippe_Billet @Bjorn.drivn

Hopefully these images will be readable :slight_smile:

Component Setup:

Error returned:

Cheers

Simon

Please, look at this solution.
Filtering on array works “backwards”:
image

1 Like

@Philippe_Billet

Isn’t that a filter within Make though?

This is a specific querystring element on a call to Sugar called “filter” - not sure it’s the same thing really?

I’m passing the “filter” definition to Sugar to allow it to pull out and return specific records.

Cheers

Simon

Sorry for the misunderstanding.

Indeed, the content of the Field Value variable does not look like an array…

Do you use Google Chrome as web browser? Integromat DevTool could help.

Could you add the blueprint of your current scenario?

Philippe

1 Like

Hi @Philippe_Billet

I’ve attached blueprint for what it’s worth.

blueprint.json (43.9 KB)

Having interrogated our logs I can see the array is being treated as a string and urlencoded when posting the QS :confused:

%5B%7B%22id%22%3A%7B%22%24in%22%3A%22id1%2C%C2%A0id2%22%7D%7D%5D is what’s passed as the filter QS element.

un-encoded version:
[{"id":{"$in":"id1, id2"}}]

should be
[{"id":{"$in":["id1", "id2"]}}]

The alternative way to do filtering in Sugar is to pass multiple QS elements with the same key…

filter[0][id][$in][]=id1&filter[0][id][$in][]=id2

Unfortunately Make seems to require the QS key as needing to be unique as you only ever get the last entry (id2) in the actual QS once it’s sent

Details on Sugar filtering are here if it’s of interest

What I’m going to have to do I think is use a standard Api call rather than the specific Notes Search one and put the whole QS into the url field as even if you map QS in the component it expects an array not a string. I can then use that later style of QS which should work.

Would be interested to see what anyone from make says about this though?

Cheers

Simon

You could also open a ticket at Make, the fact that the array is not well sent is not normal (it’s my opinion).

The API call is certainly a good idea, it may avoid unexpected transformation.

Philippe

2 Likes

Grrr turns out you can also do a POST request to the filter endpoint in Sugar.
Using POST works as it doesn’t attempt to translate the data in the post elements :rage:

As an aside, putting the following into the url and ignoring the QS mapping will work for GET…

/<api version>/<module>/filter?filter[0][id][$in][]=id1&filter[0][id][$in][]=id2

My concern would be the url field may well have a character length limit so when built dynamically may well end up losing data, especially as sugar id’s are standard UUIDs.

Well, that’s a few hours down the drain, but at least I have a way forward with POST.

Thanks for all the communication guys, we got there in the end lol

Cheers

Simon

1 Like

Great you found the “solution” eventuall @Simon_Langham .
Regarding the query parameters and possible character length: have you tried sending a POST request to that endpoint and putting the parameters inside the body as JSON?

I haven’t used SugarCRM before so not sure if it works, but might be worth a try.

3 Likes

@Bjorn.drivn

Yes, that’s exactly what I ended up doing as the post data is not translated and everything worked first time!

Incredibly frustrating especially given my knowledge of Sugar but I wasn’t aware the POST option was available for retrieving data :man_facepalming:

Still, my investigations did help me solve an issue for someone else, so I guess it’s swings and roundabouts right? :slight_smile:

Cheers

Simon