Asynchronous operations in AP.jira.WorkflowConfiguration.onSave

Hi there, I am using AP.jira.WorkflowConfiguration.onSave to save post function’s configuration. However, I would like to run an async operation just before saving the configuration.

When I convert callback function to async and run await statements, the config sent to Jira is malformed and the purpose is not met.

If I do not put await before ‘async’ operation, the configuration is saved properly by Jira, but the chance of running the operation is not guaranteed, as the page is totally navigated to new page.

Did anyone come across this situation? any idea on how to deal with this?

Thanks in advance.

Hi @anon62119125,

Is it possible to share some code to help explain this?

Regards,
Dugald

Thanks @dmorrow for your response. Here is some code

componentDidMount() {
  const _that = this;
  AP.jira.WorkflowConfiguration.onSave(async () => {
    const { config } = _that.state;
    await someAsyncOperation('workflow', config);
    return JSON.stringify({ config });
  });
}

If I remove async/await, config is saved as expected, but there is no guarantee that someAsyncOperation is executed.

If the code is as is (with async/await), the config is not saved as expected, since Jira is not expecting the callback to return a promise.

1 Like

We would love for the AP.jira.WorkflowConfiguration.onSave API to be asynchronous too. Sadly it isn’t built that way @anon62119125

I have asked a few times in the past but never got anywhere. The same request would apply to the conditions and validators Javascript APIs also.

Our use case is storing customer’s configuration, that includes custom code, in our systems instead of relying on Jira’s internal workflow configuration storage, which has caused several problems in the past, due to the mechanism by which those configurations are passed around in URLs when loading the “view all my postfunctions on this transition” page.

2 Likes

@jbevan - did you find any alternative? Do we have any issue to watch out for, if Atlassian is making changes on this front? Thanks.

Hi @jbevan and @anon62119125,

I’ve created [ACJIRA-2127] - Ecosystem Jira to suggest this improvement.

Regards,
Dugald

3 Likes

We used the following workaround to migrate saved postfunction configurations during the GDPR API switch of 2019.

When a postfunction is triggered, Atlassian send the configuration that app vendors provide via the synchronous JS API in the webhook. We took a hash of that config, modified it and stored the new, GDPR compliant config in our systems, and did work using the new modified config. Every time we received a webhooks with a configuration payload that matched a hash we already had, we used the modified payload we stored. Every time a customer viewed the edit page for the workflow postfunction, we checked if we were storing a modified version of their configuration and presented that to customers instead.

It didn’t cover cases where postfunctions were created, only those which actually got triggered.

Another workaround we haven’t tried it to rely on the behaviour that when a postfunction is saved, the next screen that the customer sees lists out all the postfunctions, so app vendors should get an HTTP request to render a description of the postfunction, allowing us to see the configuration that was saved and do something with it. However, this may not work if the customer navigates away from that page before all the iframes have successfully loaded.

Thanks @jbevan for your detailed response. Unfortunately, none of this works for me, as I want to specifically capture the event of post function creation/editing. I am hoping for Atlassian to fix the issue as soon as possible.

Cheers!

I am surprised nobody complained about the synchronous behavior of onSave and, more importantly, onSaveValidation. What if you need to validate the configuration of the workflow extension in an asynchronous manner, for example through a REST call?
And what if you are simply using an AtlasKit Form, which handles validation when you click on the Submit button (which you have to simulate, obviously, since the Submit button of workflow extension configuration screens is outside of your iframe)?

1 Like