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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

229 views 1 18
Join discussion

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