How to check condition using For and If statement in SIL programming

Hi I am trying to figure out the fallowing scenario using SIL Condition post function on Jira if any of the linked issue statuses is Rejected auto transition the current issue or neglect the transition

string value = linkedIssues(key);
 for (string link in linkissues) {
    if(%link%.status != "Rejected") {
       return false;
        } else {
       autotransition("Reject",key);
       boolean exists = true;
       }
}

Please sujjest the best way to check this

1 answer

Hi,

 

you confuse 2 things. Post function is something different and condition is something different. If you try to combine it... maybe do sth like this:

string issueKey=key;
string [] values = linkedIssues(key);
boolean isAnyLinkRejected=false;
for (string linkedIssue in values) {
    if(%linkedIssue%.status == "Rejected") {
		isAnyLinkRejected=true;        
    } 
}
 
if(isAnyLinkRejected){
	autotransition("Reject",key);
}

It should be ok now. If not let me know.

Work also on your programming skills because you made several "big"  mistakes in your code

Michał, if I can add something: I would go for escaping the for loop as soon as you will hit the link to rejeceted issue. It would be slightly more efficient:

string issueKey=key;
string linkedIssueKey;
string[] values = linkedIssues(issuekey);
boolean isAnyLinkRejected=false;
number numberOfLinks = size(values);
for (number i=0; (i<numberOfLinks && isAnyLinkRejected == false); ++i) {
    linkedIssue = values[i];
	if(%linkedIssue%.status == "Rejected") {
        isAnyLinkRejected=true;        
    } 
}
 
if(isAnyLinkRejected){
    autotransition("Reject",issuekey);
}

Not much difference if there are few links on the issue, but noticeable difference if there are tens of them.

I agree it will be more efficient especially if you will have many links.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

64 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you