JIRA Behaviours- validators bound to issue opened in the background

Christian Czaia _Decadis AG_
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.
August 19, 2012

Hi all,

my question is related to an issue concerning the current baheviours plugin. Maybe someone of you guys can help me out...

That's the problem:

If you set up a Behaviours action for "Project A" only, and you hit the "Create Issue" button and a "Project A" issue was on screen at the time, the behaviors will continue to fire even if you switch to "Project B" on the top of the create form. And the opposite is true. If you hit the "Create Issue" button while you are on a "Project B" issue, and then switch to "Project A" (where the Behaviour should now be triggered) nothing happens. If you are not at an issue page, it will work

It's not only the project the behaviour seems to be bound to the issue type that's been opened in the background. Looking at the source code the problem could be somewhere here:

AJS.$(document).ready(function() {
    // todo other forms possibly
    var selectors = ["form[id='issue-workflow-transition']", "#issue-create", "form[id='issue-edit']", "form[id='subtask-create-details']"];
    var behaviourRequired = false;
    AJS.$.each(selectors, function(i, v) {
        var el = AJS.$(v);
        el.unbind('submit', submitForm).bind('submit', {docRoot: AJS.$("body")}, submitForm);
        if (el.length) {
            behaviourRequired = true;
        }
    });


    var issueId = AJS.$("#key-val").attr('rel');
    console.log ("issueId: " + issueId);
    var actionId = AJS.$("input[name='action']").val();
    if (typeof actionId == "undefined") {
        actionId = 0;
    }
    console.log ("actionId: " + actionId);
    // if we have a pid and issue type use that
    var issueTypeId = AJS.$("input[name=issuetype]").val();
    console.log ("issueType: " + issueTypeId);
    var pid = AJS.$("input[name=pid]").val();
    console.log ("pid: " + pid);


    // get list of validators
    console.log(typeof(issueId));
    console.log(issueId);
    if (behaviourRequired && typeof(issueId) != "undefined") {
        AJS.$.get(AJS.params.baseURL + "/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/validators.json",
            {issueId: issueId, actionId: actionId},
            function (data) {
                addFieldListeners(AJS.$("body"), data, true);
            }
        );
    }
    else if (typeof(pid) != "undefined" && typeof(issueTypeId) != "undefined") {
        AJS.$.get(AJS.params.baseURL + "/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/validatorsByPid.json",
            {pid: pid, issueTypeId: issueTypeId, actionId: actionId},
            function (data) {
                addFieldListeners(AJS.$("body"), data, true);
            }
        );
    }

    AJS.$(document).bind('dialogContentReady', function(event, dialog) {

        actionId = AJS.$(".aui-popup").find("input[name='action']").val();

        // console.log(dialog.$popup);
        // console.log(dialog.$popup.attr('id'));

        pid = dialog.$popup.find("#project").val();
        issueTypeId = dialog.$popup.find("#issuetype").val();

        // console.log("pid: " + pid);
        // console.log("issueId: " + issueId);

        // not always true
                                                             // edit issue popup
        var formIds = "#issue-workflow-transition,#assign-issue,input[type='hidden'][name='id'],div.issue-setup-fields";
        if (dialog.$popup.find(formIds).length) {

            // todo: duplicated above
            if (typeof(issueId) != "undefined") {
                AJS.$.get(AJS.params.baseURL + "/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/validators.json",
                    {issueId: issueId, actionId: actionId},
                    function (data) {
                        addFieldListeners(dialog.$popup, data, true);
                    }
                );
            }
            else if (typeof(pid) != "undefined" && typeof(issueTypeId) != "undefined") {
                AJS.$.get(AJS.params.baseURL + "/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/validatorsByPid.json",
                    {pid: pid, issueTypeId: issueTypeId, actionId: actionId},
                    function (data) {
                        addFieldListeners(dialog.$popup, data, true);
                    }
                );
            }

I guess you would have to check if you're editing an issue (which should get the behaviour assigned to that particular issue type) or want to create a new issue in which the current issue id should be ignored.

Hope that you know what I mean...

3 answers

1 accepted

0 votes
Answer accepted
Christian Czaia _Decadis AG_
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.
October 25, 2012

I think we ve identified the bug. The unwanted behaviour mix has been the result of some merging of existing and new "behaviours". We`re currently testing the fix but if you want we could provide the fix here?...

Cheers Christian

Oriol Esplugas December 4, 2012

Hello,

We have the version 0.5.0 of the plugin and this problem happen. What is the solution for the problem please?

The problem happens when we wnt to create an issue in the issue page.

Our customer have the JIRA 5.0.7 and don't have migrate.

0 votes
Christian Czaia _Decadis AG_
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.
August 26, 2012

Another confusing thing is the output of the firebug console when I navigate to a view issue screen. Is this normal?

Won't let me upload attachments. Here's the text only version:

issueId: 10902
actionId: 0
issueType: undefined
pid: undefined
string
10902

0 votes
JamieA
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.
August 19, 2012

This should be fixed in the latest release.

Christian Czaia _Decadis AG_
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.
August 20, 2012

Hey,

I know. I also commented on the issue but I hoped to get your attention in this forum...My problem is that I'm pressed for time... My current customer wants to go live with a system but not until this issue is fixed. That's why I've been asking all those questions about you maintaining the plugin etc. The second thought was to search for the bug and locally fixing it for now. I know that you don't have that much time. That's why I asked if you could point me to the right spot since I was just browsing the source randomly...

JamieA
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.
August 20, 2012

I would guess something is not getting cleared the second time the script is activated. There are one or two global variables (eg "behaviours" iirc) , I would try to clear them just inside the dialogContentReady block.

JamieA
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.
August 20, 2012

Also I think "AJS.$(document).bind('dialogContentReady'," should be changed to the NEW_CONTENT_ADDED event...

Christian Czaia _Decadis AG_
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.
August 20, 2012

Thanks for your comment, I'll check if it works!

SarahL August 26, 2012

Hi Jamie,

I am currently running into the same problem. I tried to clear all global variables as you said, but this did not do anything. Also I changed

AJS.$(document).bind('dialogContentReady', function(event, dialog) {

to

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (event,dialog) {

but this made the $popup object in the following dialog.$popup undefined.

I also simply tried to comment out the two if-clauses in

line 838:

if (behaviourRequired && typeof(issueId) != "undefined") { ...

and line 880

if (typeof(issueId) != "undefined") {...

but so far, I have no luck fixing the bug. Could you please tell me what I am doing wrong??

Thanks in advance!!

Christian Czaia _Decadis AG_
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.
August 26, 2012

When I turn on firebug it becomes clear that the issue_id of the issue opened in the background gets pulled by the script and the validators.json is being addressed. Creating an issue from the dashboard the validatorsByPid.json is being addressed.... I've attached some screenshots:

Any ideas? By the way, is the clientvaljq.js the right spot to look for the bug?

SarahL August 28, 2012

Hi,

I tried around a bit more and looked at the BehaviourManagerImpl.groovy.

I changed the

if (form["id"]) {
            issue = ComponentManager.getInstance().getIssueManager().getIssueObject(Long.parseLong(form["id"]))
            pid = issue.getProjectObject().getId()
            issueTypeId = issue.getIssueType().get("id").toLong()
            actionId = form["action"] ? Integer.parseInt(form["action"]) : 0
        }

to

if (form.isCreateIssue != "true"&& form["id"]) { // only if editing form displayed
           issue = ComponentManager.getInstance().getIssueManager().getIssueObject(Long.parseLong(form["id"]))
            pid = issue.getProjectObject().getId()
            issueTypeId = issue.getIssueType().get("id").toLong()
            actionId = form["action"] ? Integer.parseInt(form["action"]) : 0
        }

which works for an easy test case but doesn't work for our scenario with lots of configured behaviours on different fields.

Jamie, maybe this is something you could follow up on? Thanks in advance!

Christian Czaia _Decadis AG_
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.
September 10, 2012

Hey @Jamie,

do you think you got a minute to look at the updates from Sarah? We are to go live tomorrow and I have to tell the users about the bug (unless I fix it until tomorrow...won't happen I guess).

Just a quick look since you are the one who knows the code best!

Thank you very much!!

Christian

JamieA
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.
September 10, 2012

Christian, I'm really sorry, there is nothing I can do today or tomorrow. Maybe next week time allowing. But what about jira 5.1 and above... what are your plans for that?

Christian Czaia _Decadis AG_
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.
September 11, 2012

Hi Jamie,

no problem. Thanks for the response anyway. My customers doesn't plan to upgrade anytime soon and if inline editing is the killer for your plugin they probably won't use that feature at all. My problem is that I don't see any real alternative to validate fields in realtime...Any help (whenever you got time) is really being appreciated!

Thanks

Christian

Christian Czaia _Decadis AG_
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.
December 20, 2012

Hi Jamie,
with joy I noticed in early November, that you've decided to keep behaviours plugin alive. Since I don’t have any contact on you I’m addressing a question right here…

After fixing this bug () locally we now have two more suggestions that would be handled by a student, who is about to write a university paper about JIRA and your plugin

Firstly, we would like to have the possibility of inline-editing of the behaviors in the admin area, Secondly, an import / export function of the mappings and behaviors would be highly desirable.

The student could make these changes for us, but he would like to discuss them with you, so that these could be included in the update process.
Since we‘re still using an older version of Jira (5.0.7) he would port and test his changes on the latest version of your plugin, if you agree.
What do you think about this? If you want to get in contact with our student he’d be very happy to hear from you. His address is: J.Riedinger@decadis.de.

Merry Christmas and thanks for the plugin,
Christian

JamieA
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.
December 20, 2012

Hi Christian,

In general happy enough to speak to anyone but it would be pretty brief, my spare time is going into groovy jql functions at the moment.

The mappings and behaviours are just properties so shd be easy to get out. Importing would involve mapping custom field ID to name, which is not so easy. Same problem with a general export/import in jira.

Why don't you pass on my email, it is "firstname at lastname @ gmail.com". PS: subsitute my first and last names... that seems to trip people up.

cheers, jamie

Suggest an answer

Log in or Sign up to answer