get last history changed of field by web request
Asked by Shani Levi:

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


Answers:
author: Bill Sheboy
body: Hi [@Shani Levi](/t5/user/viewprofilepage/user-id/5556644)

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:

* *List iteration* : <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/#Combined-function-examples>
* *Conditional list filtering* : <https://community.atlassian.com/t5/Automation-articles/Filtering-smart-value-lists/ba-p/1827588>
* *Additional conditional functions to help* : <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/>
* *Create Variable action* : <https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Create-variable>
* *Split() and other text functions to parse the result from the variable* : <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#split-String-separator->

Kind regards,  
Bill

comments: author: Shani Levi
body: 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


author: Bill Sheboy
body: 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-->


author: Shani Levi
body: 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?


author: Shani Levi
body: I solved it with this command:

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

Thanks Shani


author: Bill Sheboy
body: 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.


Tags: cloud

jira-cloud