Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-FreshServiceCustomObjectRecord filter returning one page of results #11

Open
rasimmers opened this issue Oct 16, 2023 · 6 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@rasimmers
Copy link
Contributor

Expected Behavior

Using the filter for Custom Object Record (https://api.freshservice.com/#list_all_custom_object_records) should filter records and return all pages.

Current Behavior

The Filter applies, but there is no next page link and incrementing the page does not return different results resulting in an infinite loop.

Possible Solution

Waiting on response from Freshworks development on how pagination works. Remarked -Filter parameters until remediated.

@rasimmers rasimmers self-assigned this Oct 16, 2023
@rasimmers rasimmers added the bug Something isn't working label Oct 16, 2023
@KiskaSanchez
Copy link

@rasimmers test

@KiskaSanchez
Copy link

@rasimmers test

What is the status of this?

@KiskaSanchez
Copy link

KiskaSanchez commented Mar 1, 2024

To do:

  • this

@r-wilkins
Copy link

When reviewing what was causing the issue after reenabling the filter switch I noticed the logic of the Loop condition variable and the if statement for the filter switch was flawed because Freshservice seems to keep returning values for any page number when doing a filter for a custom object. This indeed seems like a bug but there are two different work arounds we can do.

The first one is the update the IF Statement and the Loop Condition variable
The If Statement on lines 243-254 ran every single time and didn't check to see if it needed to loop again as well. This resulting it setting loopcondition back to false everytime because it always found 2 records.

 if ($PSBoundParameters.ContainsKey('filter')) {
                    #Pagination is manual for results returned from filter
                    Write-Verbose ('Using filter pagination for page {0}' -f $page)
                    #Manually increment page
                    $page++
                    #Update query
                    $qry['page'] = $page
                    $uri.Query = $qry.ToString()
                    $uriFinal = $uri.Uri.AbsoluteUri
                    #Update loop condition based on return results
                    $loopCondition = $content."$($objProperty)".Count -eq 0
                }

By including an additional condition here and updating the initial loop condition variable to say $result.Headers.Link -like "" this will aid in the loop logic easier than saying !$result.Headers.Link
I made a change to our Module by updating the $loopCondition Variable on line 241 and the filter if statement on line 243.
from

$loopCondition = !$result.Headers.Link

($PSBoundParameters.ContainsKey('filter'))

To

$loopCondition = $result.Headers.Link -like ""

if ($PSBoundParameters.ContainsKey('filter') -and !$loopCondition) {

This resulted in it fixing the filter logic for us for custom objects. I saw something similar happen with the get-fsasset filter switch too but haven't made any changes to that yet to test.

2
The other method is to possibly incorporate additional counting of the loop using the $content.meta.total_records value.

We other vendors with similar API outputs that allow us to see how many records are in a result for a specific table. Freshservice previously did not provide this from what I saw last year.
So it shouldn't be too hard to implenment some additional counters to keep track of how many records it just read compared to the total per page compared to the overall total.
I don't have the overall logic written out just yet for this particular module due to how I have to test my changes but I can find something works to be reviewed by the Flycast Partners team.

@r-wilkins
Copy link

The other Modules that have the same issue with their filter looping are
Get-FreshServiceAgent
Get-FreshServiceAsset
Get-FreshServiceCustomObjectRecord
Get-FreshServiceProjectTask
Get-FreshServiceRequester
Get-FreshServiceTicket

I was able to find these by referencing the $loopCondition Variable in any other Modules. I have confirmed that updated the asset module correct an issue where it would always warn about 40 page limit even on a empty result for a filter.

@DavidHummingbird
Copy link

Any updates on this? I need to use -Filter on Get-FreshServiceCustomObjectRecord, but because it's remarked out I can't use it currently :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants