Forums

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

get last history changed of field by web request

Shani Levi August 11, 2024

hello,

 

I need to get last history changed of field "Target Sprint" from automation with web request.

the web request work good, when I display this log {{webResponse.body.changelog.histories.items.field}}

I get this result: 

 

 [Target Sprint], [Feature End Date], [Target Sprint], [Feature End Date], [Target Sprint], [Feature End Date]

but when I try to get last update of "Target Sprint" with this:

{{webResponse.body.changelog.histories.reverse().items.filter(it => it.field == "Target Sprint").first.to}}

I get empty result.

how can I get last value in history of "Target Sprint" field?

 

Thanks Shani

1 answer

0 votes
Bill Sheboy
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 11, 2024

Hi @Shani Levi 

Short answer: you may use smart value, list filtering and created variables to get the information you are seeking; or, you could use a rule triggered on a change to the field and save the changes in a custom field...which could be reviewed later, as needed.

 

More information...

First, I do not believe there is a reverse() or a filter() function for smart value lists.

 

The REST API endpoints for the changelog use paging, and thus even if those above functions existed, you would not necessarily get a result unless the automation rule performed paging of the changelog results using multiple calls with Send Web Request.  https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-changelog-get

For the remainder of my suggestions, I will assume there is a change to the Target Sprint field in the first page of results from the changelog lookup...which by default are returned with the most recent one first.

 

You could use list iteration and conditional filtering to extract the entries for Target Sprint changes, adding a delimiter, and saving the result in a created variable.  Then, split the variable on the delimiter and grab the first entry.

Here are some references to help you do that:

 

Kind regards,
Bill

Shani Levi August 11, 2024

but how I can get the value of "Target Sprint" from the history?

becouse I need to know if the Target Sprint was updated once time to value that is not empty.

 

Thanks Shani

Bill Sheboy
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 11, 2024

If your rule is triggered on a change to that specific field (e.g., Issue Field Changed trigger), you may used the changelog smart value to check the {{fromString}} and {{toString}} to learn what it previously and currently contains:

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/#--changelog--

 

Shani Levi August 11, 2024 edited

I tried this already and I got empty result,

{{#changelog.customfield_10181}}{{fromString}}{{/}}

or this {{changelog.customfield_10181.fromString}}

 

the automation trigger is on changes in field customfield_181 (Target Sprint field).

do you know why the changelog not work?

Shani Levi August 11, 2024

I solved it with this command:

{{#changelog.Target Sprint}}{{fromString}}{{/}}

 

Thanks Shani

Like • Bill Sheboy likes this
Bill Sheboy
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 12, 2024

In some cases, the smart value or custom field may be used...but in others only one or the other works.  I should have noted that the changelog in rules works more consistently with the smart value, not the custom field id.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events