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

AkashD August 18, 2016

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

0 votes
Michael Partyka
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 18, 2016

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

Błażej O_
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 18, 2016

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.

Michael Partyka
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 18, 2016

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

Suggest an answer

Log in or Sign up to answer