Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Linking Issue in IF Statement

Midnite8
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 18, 2021

In my SIL script, I am trying to link an issue but it is not working in my IF statement. Below is the part of my script:

if(contains(customfield_1234,"FieldName"))
{
string newKey = createIssue(key.project, "", "Task", "summary!",priority,"description","",DueDate,"",{},custom_field_mapping);
%newKey%.customfield_1234 = customfield_1234;
linkIssue(key, newKey, "Relates");
}

 I think the problem is that it is trying to link an issue that technically doesn't exist since it is wrapped in an IF statement?

Jira log error:

Cannot cast string >>Project_Name<< to an issue. Invalid issue key format. Are you running the script from create screen ?

2 answers

0 votes
Lilliana Goldner
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 19, 2021

Good evening, I seem to be getting the error "else without if" when I try to design this code.

I had it working previously, but for the life of me cannot see where im going wrong here.

 

// Code is inside a button press actionevent

 

String amount = jTextFieldBlockAddAmount.getText();

String Loc = jTextFieldBlockAddLoc.getText();

if (amount.equals("") || (Loc.equals("")));

{

Component frame = null;

JOptionPane.showMessageDialog(frame, "Please fill in the two sections before adding a new block", "Insert Error", JOptionPane.ERROR_MESSAGE);

}

else {

GreBlock block = new GreBlock(new Date(), amount, Loc);

Grechain.NewBlock(block);

jTextFieldBlockAddAmount.setText("");

jTextFieldBlockAddLoc.setText("");

Component frame = null;

JOptionPane.showMessageDialog(frame, "A block has been added to the blockchain");

System.out.println("Block Successfully Added");

}

 

What am I missing here? if the else statement begins to work the functions within it all work fine, so there is no problem there.

 

Thanks in advance,

 

 

great people me

0 votes
Fabian Lim
Community Champion
August 18, 2021

Hi @Midnite8

Try printing the new key with a runnerlog and you will see if it's creating the issue or not.  You are correct with your assessment, so something happened with the create function, maybe one of the fields are missing or have not been configured.

Thanks

Midnite8
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 18, 2021

@Fabian Lim 

Interesting, I commented out the linkIssue line and it still has the same error. I checked both fields in the createIssue lines and made sure they exist in the screen associated with the IssueType.

I have a slightly different version of the script with everything the same except that I don't have any IF statements that include a linkIssue and it works.

Fabian Lim
Community Champion
August 18, 2021

It's actually the create function that is causing the issue.  Why don't you share the whole script?

Fabian Lim
Community Champion
August 19, 2021

For the runnerlog: https://confluence.cprime.io/plugins/servlet/mobile?contentId=6558203#content/view/6558203

It would be runnerLog("new issue:" + newKey);

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events