Forums

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

How to pull out the last added value from the fixVersion field?

Elena April 28, 2022

Hi,
We need to develop a sil script where the last added version in issue is needed. What are the ways to pull the last added value from the fixVersion field?

1 answer

0 votes
Thiago Masutti
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 2, 2022

Hi Ellen.

There's nothing on the stored data that will tell when a version was added, so I don't know if there's a reliable way to tell which version was recently added.

Considering how DB works we may assume larger ID values are more recent (I wouldn't call that bulletproof, but it may work on most cases).

Then you may choose to work with admGetProjectVersions and admGetProjectVersion to get the version with the higher ID (first field from admGetProjectVersion).

versions.png

In this example I would assume 1.5 is the more recent version based on the ID (10101).

https://confluence.cprime.io/display/SIL/admGetProjectVersion 

https://confluence.cprime.io/display/SIL/admGetProjectVersions 

 

I hope that helps.

Kind regards,
Thiago Masutti

Elena May 10, 2022

Hi Thiago.
To clarify, we need to select the last value from the field in the task. As I understand it, your example is pulling a value from a project. Perhaps there is some way to pull the value out of the task?

Thiago Masutti
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 11, 2022

Hi Ellen.

If you need to check the latest value assigned to a Jira Issue, then you may use getFieldChanges .

 

The below will get all the changes applied to the field.

getFieldChanges("SCRUM-14", "Fix Version")

jira-sil-versions.png

 

The below script will get the latest value for the same field.

JFieldChange[] changes = getFieldChanges("SCRUM-14", "Fix Version");

JFieldChange latestChange = changes[0];
date newest = latestChange.changeDate;

for (JFieldChange change in changes) {
if (change.changeDate > newest) {
latestChange = change;
}
}

return latestChange;

jira-sil-versions-2.png

Kind regards,
Thiago Masutti

Elena May 11, 2022

Thanks, it worked!
How to get version name? For further actions with the script, we need to pull out the version name. For example, set the variable:
string lastVersion;
and assign the resulting value to it, in your example it is "Version 3.0"

Thiago Masutti
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 11, 2022

Hi Ellen.

That returns a JFieldChange object. The structure is detailed in https://confluence.cprime.io/display/SIL/Predefined+structure+types#Predefinedstructuretypes-JFieldChange 

You may use one of the following depending on what you need.

latestChange.newVal

latestChange.newValString

 

jira-sil-versions-3.png

 

Kind regards,
Thiago Masutti

Elena May 11, 2022

Hi Thiago.
It worked. Thank you.
I noticed that if, when editing a field, the old value is deleted, changed to another value and then saved, then the log is empty. Is there a way around this to always get the latest value?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events