WorkflowConfiguration.trigger() is executed too many times and saves undefined

47 views
Skip to first unread message

Jon Bevan

unread,
Feb 24, 2017, 7:24:56 AM2/24/17
to Atlassian Connect Dev
Problem:

When I create a new workflow postfunction, "undefined" is sent to the /secure/admin/workflows/AddWorkflowTransitionFunctionParams.jspa endpoint as the config for the post function.

This occurs on at least 3 JIRA Cloud instances with development mode enabled and either AP 5.0.0-beta.36 or 5.0.0-beta.38 - but the behaviour does not exist on at least one other instance which has AP 5.0.0-beta.38.

I can reproduce the behaviour on different machines in different browsers and in incognito/private browsing as long as I'm using one of the broken instances.

The code works fine with AP 3.0.0, so nobody in production has been affected by this yet :)

Details:

I have logging inside my onSaveValidation and onSave handlers, both of which are registered only once and both of which are being executed successfully. However, each of them is called 3 times:

import {toByteArray, fromByteArray} from 'base64-js';
import { TextDecoderLite, TextEncoderLite } from 'text-encoder-lite';

AP.require(['jira'], (jira) => {
    jira.WorkflowConfiguration.onSave((() => {
        console.log("Registering workflow config save handler");
        return stringifyConfig;
    })());

    jira.WorkflowConfiguration.onSaveValidation((() => {
        console.log("Registering workflow config validation handler");
        return validateForm;
    })());
});


function encodeForStorage(str) {
    return fromByteArray(new TextEncoderLite('utf-8').encode(str));
}

function validateForm() {
    console.log("Validating form");
    return true;
}

function stringifyConfig() {
    const postFunctionConfig = {
        className: "hello world",
        uuid: 'abcd-edfgg-1234-asdad'
    };
    const encoded = encodeForStorage(JSON.stringify(postFunctionConfig));
    console.log("Saving form", postFunctionConfig, encoded);
    return encoded;
}


Additionally, I added a breakpoint using the Chrome dev tools to the trigger() function of the WorkflowConfiguration and that breakpoint is hit 5 times once the "Add" button is clicked.
There is no save handler or validation handler in scope on 2 of those executions:

// from all.js around line 3399 as formatted by Chrome dev tools
   
var i = {
        onSaveValidation
: function(k) {
            e
= k
       
},
        onSave
: function(k) {
            h
= k
       
},
        trigger
: function() {
           
var m = true;
           
if (b(e)) {
                m
= e.call()
           
}
           
var l;
           
if (h) {
                l
= h.call()
           
}
           
// On two of the executions of this function, e and h are undefined, so the value
           
// set on k is "undefined"
           
var k = {
                valid
: m,
                value
: m ? "" + l : undefined
           
};
            AP
.jira._submitWorkflowConfigurationResponse(k);
           
return k
       
}
   
};


I have not managed to figure out why trigger() gets called 5 times... I am not calling it from my JS as you can see from above, I'm just clicking on the "Add" button.

Whilst debugging this I can get the configuration to save correctly, as the breakpoint pauses interfere with some timing or something which prevents the "undefined" value being the one that gets posted off to JIRA.

I don't know what to do at this point but I can't develop this part of my add-on anymore - I am very happy to provide more details if required or even perhaps access to a JIRA instance if someone from Atlassian is able to help.

Jon Mort

unread,
Feb 27, 2017, 10:13:39 AM2/27/17
to Atlassian Connect Dev
I have created a repo that reproduces this forked from the Atlassian Labs workflow example: https://bitbucket.org/jonmort/atlassian-connect-jira-workflow-post-function-example

After adding the post function you would expect to see https://www.evernote.com/l/AAKkk1KYMXpA9Z5ATL0RssrCX2TPUOkHNsQB/image.png which works find on jonmort.atlassian.net but fails on jdbevan.atlassian.net, both of which have the same AP version.

--
You received this message because you are subscribed to the Google Groups "Atlassian Connect Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to atlassian-connec...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Jon Mort
Engineering Research and Development|Adaptavist

Robert Massaioli

unread,
Mar 1, 2017, 12:10:17 AM3/1/17
to Atlassian Connect Dev
Thank you for raising this bug report. I have passed this on to the ACJS development team who will be looking into this bug report and should get back to you soon. Cheers.
To unsubscribe from this group and stop receiving emails from it, send an email to atlassian-connect-dev+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Jon Bevan

unread,
Mar 2, 2017, 11:30:53 AM3/2/17
to Atlassian Connect Dev
Thanks Robert - do you have a ACJS ticket number I can track?
Reply all
Reply to author
Forward
0 new messages