Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

SIL: How to get values of custom fields defined in a list

Hello!

We had a question in Moscow Atlassian User group on how to get the value of a custom field in SIL if the name of the field is defined in an array.

I think code will explain it better:

string [] keys = selectIssues("key = SCRUM-22");
string [] fields = {"my text field"};
for (string k in keys) {
    for (string field in fields) {
        runnerLog(k.#{field});
    }
}

As you can see I get issues by a JQL query. Then I define an array of the names of fields which values I want to print out for selected issues. Then I iterate over all issues and inside this loop I iterate over all fields in the fields array and print out the value.

If I try to compile this code I will get an error:

Screenshot 2020-06-26 at 12.34.15.png

The error is for this line:

runnerLog(k.#{field});

SIL tries to find a field with the name "field" (SIL does understand that "field" is a variable, it looks for a field with the name "field") and SIL can not find such field and throws an error.

If we change this line with this one:

runnerLog(k.#{my text field});

Then everything will compile correctly and we will get what we want. Does it mean that we can not define names of custom fields in an array, instead we should always provide implicit names? Imagine we have 50 fields to select. In this case our code will look awful.

The answer is there is a way to make it clean.

SIL has this symbol %. If you surround a variable with this symbol, then SIL will treat this variable as a variable. It is needed in ambiguous situations like ours.

Let's surround the field variable with the % symbol like this:

runnerLog(k.#{%field%});

Here is the complete code:

string [] keys = selectIssues("key = SCRUM-22");
string [] fields = {"my text field"};
for (string k in keys) {
    for (string field in fields) {
        runnerLog(k.#{%field%});
    }
}

Now this code compiles and works as expected.

0 comments

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New cloud apps roundup - June 2021

Since our last roundup in April, Atlassian's Marketplace Partners have added over 100 new cloud apps to the Atlassian Marketplace to help your teams work more efficiently. Let’s take a quick look a...

368 views 5 11
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you