Solved

Creating Reports via Ruby SDK

  • 13 July 2022
  • 3 replies
  • 30 views

Hi, I’m Alejandro :)

I'm working on automating report creation via the Ruby SDK.

To be able to create reports, I was following these instructions: https://sdk.gooddata.com/gooddata-ruby-doc/docs/working_with_reports

But this way of creating reports :

project.compute_report(left: project.metrics.first, filters: [[label, :not, 'San Francisco', 'Prague']])

only allows me to create filters as IN or NOT IN, per what I can see in the method itself.

In my case I want to create a report with 2 filters with the expressions:
 Year is this year    (so this would be Attribute = Value)
<attribute > where Contact is Valid is equal to 1. (so this would be attribute where metric is equal to 1)

How can I accomplish this? I can't seem to find examples or good enough information related to this or how to do it.

I'll appreciate any help,

Thanks
Alejandro

icon

Best answer by alejandro.rivera 14 July 2022, 14:10

View original

3 replies

Userlevel 2

Hi Alejandro,

The most straightforward way to accomplish what you are trying to do would be to pull the report unfiltered and then filter the result set programmatically inside Ruby. I’d iterate over the rows and filter the final result set based up variables you’d establish elsewhere.

I think you’ve already seen the page, but to be sure → the essentials of of parsing report data are in the Working with report results subsection found here: https://sdk.gooddata.com/gooddata-ruby-doc/docs/working_with_reports#working-with-report-results

Would this option work for you?

Hey Jan,

Thanks for responding!

Although my goal with this is to be able to create and saved the reports already filtered.

I did find a workround though,  I actually had to modify this method

Specifically this line

'filters' => ReportDefinition.create_filters_part(filters, :project => project)

I’ve changed it to:

'filters' => filters

And I can just past the filters as:

[{'expression'=> "Expression here"} ,  {'expression'=> "Expression here"} ]

This doesn’t have limits and I can create any filter that I want, I don’t know why this is not possible with the Ruby SDK allowing only IN or NOT IN filtering.

 

Thanks anyway!

Alejandro

Userlevel 2

It’s great that you were able to find a workaround.

Regarding why the Ruby SDK doesn’t offer this out of the box: I am not sure. I’ll do a bit of a follow-up internally and see if this is something we could include in the future. Thank you for sharing it in public - it’s helpful to anybody who might come along with a similar problem in the future.

Reply