Could you write an automation to find out who last edited a specific field?
Asked by Kelly Arrey:

Hi Community,

Could automation (on Jira Software Cloud) figure out who was the last person to edit a specific field, and set a label if that person belongs to a specific Jira group? Is that even possible? If so, could someone outline approximately what that would look like? I would run the rule against a JQL filter as part of a one-time cleanup effort. Thanks for any ideas you can offer.

Kel


Answers:
author: Darryl Lee
body: Ohai [@Kelly Arrey](/t5/user/viewprofilepage/user-id/510430) and [@Mikael Sandberg](/t5/user/viewprofilepage/user-id/853579) ...

\*TECHNICALLY\* you could use the REST API to get the changelog for every issue, like this:

<https://YOURSITE.atlassian.net/rest/api/3/issue/BUG-5?expand=changelog>

And then, maybe, you could filter every change for a specific field...

And then, maybe, you could grab the _last_ of those changes...

And then, maybe, you could identify the author of that change...

And **then** you could then do a check if that author is in a specific group

And IF SO, apply the label.

But this would all be a little hairy, for sure.

Maybe I'll give it a go later tonight. :-}

comments: author: Kelly Arrey
body: Thanks [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) that sounds pretty hairy alright. Thanks for thinking about it but please don't spend any more time on it.


author: Darryl Lee
body: Heh, I couldn't help myself. Got it to work, with the following caveat:

* It only works if the field change was within the most recent 100 changes to the issue

Anywho, we start with a [**Web Request to the Jira API**](https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Send-web-request-using-Jira-REST-API/ba-p/1443828):
> <https://YOURSITE.atlassian.net/rest/api/3/issue/{{issue.key}}?expand=changelog>

Then we create a variable that I'm calling ***recentFieldChangers*** . What it's doing is getting the most recent changes to the issue (it maxes out at 100, hence the limit\*), and checks to see if it is for the field **Checkboxes** . If so, then it outputs the **accountId** for whomever made that change (the **author**), and separates these accountIds with a semicolon.
> {{#webResponse.body.changelog.histories}}{{#if(equals(items.get(0).field, "Checkboxes"))}}{{author.accountId}}{{\^last}};{{/}}{{/}}{{/}}

Then I use the ***split*** function to turn that text string of semicolon-separated accountIds into a "list" object that I can select the first of:
> {{recentFieldChangers.split(";").first}}

This is then fed to **another** web request to check if that user is in the selected group. (Automation does have a function to check if a user is in a group, but it can only be used against user fields in an issue, not arbitrary values.)

So that web request looks like this:
> <https://YOURSITE.atlassian.net/rest/api/3/user?accountId={{recentFieldChangers.split>(";").first}}\&expand=groups

I then create a variable called ***groupMatch**.* It is going through all the groups for that accountId from above, and checking to see if it matches the group named "shift2", and if so, it outputs "shift2":
> {{#webResponse.body.groups.items}}{{#if(equals(name,*"shift2"))}}shift2{{/}}{{/}}*

And so, the last (heh) step is, compare whether {{groupMatch}} equals "shift2" and if so, then do whatever you need to do. In your case, apply a label.

Here's a picture of what this all looks like:  
![Screen Shot 2023-02-16 at 9.31.32 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/240847i6E3DC93767DC185F/image-size/large?v=v2&px=999 "Screen Shot 2023-02-16 at 9.31.32 PM.png")

++Notes:++

\* There [actually isn't a limit to the number of changes you can view](https://community.atlassian.com/t5/Jira-Software-questions/Rest-API-limiting-changelog-history-results-to-100-even-if/qaq-p/1466525). But I'm using the [**issue API endpoint**](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-get) with the expand parameter. To check issues with more than 100 changes, you would have to figure out how to do pagination in the [changelog API endpoint](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-changelog-get) to go through each batch of 100 changes, AND they are sorted in chronological order, so you'd have to go through them backwards. I'm bad at doing this with real scripting languages, much less this "pretend" one. :-}


author: Darryl Lee
body: OH, and for your purposes, you would probably still [manually trigger](https://support.atlassian.com/cloud-automation/docs/test-a-jira-automation-rule-using-the-manual-trigger/) it, but run it against a JQL lookup, so then:

![Screen Shot 2023-02-16 at 9.34.53 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/240848iD502A0D13ED699D3/image-size/large?v=v2&px=999 "Screen Shot 2023-02-16 at 9.34.53 PM.png")


author: Kelly Arrey
body: Wow! Thanks again [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322). I'm going to take some time to digest this and report back.


author: Darryl Lee
body: Heh, yeah, I realize it's a bit much. But hopefully you or somebody else can make use of it!


author: Mikael Sandberg
body: Yes and no. You can set up the rule to trigger on when the field is changed and then check and see if {{initiator}} is in the specific group. But you cannot use a one-time rule to get the history of the issue to see if the user made the change.

comments: author: Kelly Arrey
body: Thanks [@Mikael Sandberg](/t5/user/viewprofilepage/user-id/853579)


author: Dave Liao
body: I love how there are multiple correct answers in our world. ?


author: Yuliia_Borivets__SaaSJet_
body: Hi [@Kelly Arrey](/t5/user/viewprofilepage/user-id/510430)

I'm not good with automation, but as an alternative solution, I can suggest [Issue History for Jira](https://marketplace.atlassian.com/apps/1220385/issue-history?hosting=cloud&tab=overview&utm_source=Atlassian_Community&utm_medium=refferal&utm_campaign=Comment_automation-to-find-out-who-last-edited-specific-field__20230217) app. Here, you can track ***Updated by*** field, so you will see *what changes some person has made to the specific field*. All standard and custom fields can be added to the report.

![Jira updated by.png](https://community.atlassian.com/t5/image/serverpage/image-id/240925i4637291FF924398D/image-size/large?v=v2&px=999 "Jira updated by.png")

The app is developed by my team. You can try [free online demo](https://saasjettest.atlassian.net/plugins/servlet/ac/ih-demo/issue-history?project.key=MD&project.id=10009&utm_source=Atlassian_Community&utm_medium=refferal&utm_campaign=Comment_automation-to-find-out-who-last-edited-specific-field__20230217) to see how it works.

comments: author: Kelly Arrey
body: Thanks [@Yuliia_Borivets__SaaSJet_](/t5/user/viewprofilepage/user-id/4307791), good to know!


Tags: cloud

jira-software-cloud