Export Structure to excel

Alex
Contributor
November 6, 2024

Hi!

I try export structure to excel with using scriptrunner.

It works, but we want to export the structure using pre-saved filters. Is it even possible?

The example has variables such as viewSpec, expandState, clientFilter, but it doesn't say what they are and how to use them. Maybe someone has an example of using these variables with a value other than null?

4 answers

1 accepted

1 vote
Answer accepted
Alex
Contributor
November 18, 2024

Hi everyone!

I went into the source code of the Structure plugin and StructureApi and figured out how to insert filters. Maybe this will help someone.


To add filters, you need to add the Transforms parameter to ForestSpec. You can get these transformations like this - go to the desired structure, configure the filters as needed and press the export to Excel. In the browser developer console, in the Network tab, find the Excel post request and in the "Payload" tab, take forestSpec.

Now replace the line

def spec = ForestSpec.structure(structureId, helper.userManager.getUserByName(userName))

with

List<ForestSpec.Transformation> transformations = [
new ForestSpec.Transformation("com.almworks.jira.structure:filter-jql", [
"showSubItems": false,
"jql": "status not in (Closed) AND duedate <= endOfMonth()",
"level": null,
"keepNonIssues": false
])
]

ForestSpec spec = ForestSpec.builder()
.setStructureId(structureId)
.setUserKey(helper.userManager.getUserByName(userName).key)
.setTransformations(transformations)
.build() as ForestSpec
exporter.configure(viewId, viewSpec, spec, expandState, clientFilter)

 

0 votes
Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 7, 2024

Also, if you are open to trying alternative approaches, try the Structure integration in Better Excel Exporter.

As you are asking in the context of ScriptRunner, I assume you need programmatic exports. If that's the case, then the Better Excel Automation app can implement those use cases for you! It adds automation capabilities to the exports produced by the exporter app.

(Discl. both recommended apps are developed and supported by our team. They offer free triers and the automation app is free for everyone!)

 

Alex
Contributor
November 18, 2024

Thanks for the answer! We use Better Excel Exporter, but we have a task where we need to unload the structure on a schedule and put it on a remote server, which your plugin, unfortunately, cannot do.

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 7, 2024

Hi @Alex

The example that is shared in the Structure documentation is pretty old.

The correct approach will be to use the @WithPlugin and @PluginModule annotations as shown in this ScriptRunner Documentation.

Let me know how it goes.

Thank you and Kind regards,
Ram

Alex
Contributor
November 18, 2024

Hi! Thank you!
But the point of the question was not about the script example itself. We rewrote it using annotations before this discussion was created. The question was that it is not described anywhere how to apply filters when unloading a structure and unfortunately neither your documentation nor tempo's documentation describes this.

0 votes
Vronik
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2024
Alex
Contributor
November 18, 2024

Hi, ty!
I saw that topics before asking and it's not helped

Suggest an answer

Log in or Sign up to answer