How to create an automation rule that compares the field Reporter with Request participants?
Asked by Nahuel Logghe:

Hello!

I want to create a rule that checks if the Reporter is set as a Request Participant and if that is the case to remove it from the field.

Since request participants have multiple values I have no clue how to achieve this.

Ideas?


Answers:
author: Anna Hryhoruk _Appfire_
body: Hello [@Nahuel Logghe](/t5/user/viewprofilepage/user-id/5433828) ,

Are you considering any marketplace apps? If yes, I can show you how to make one using the Power Scripts app and the SIL scripting language.   

The SIL script like this will do what you need: checks if the reporter of an issue is listed among its participants, and if so, it removes the reporter from the list of participants associated with the issue.

```
string[] AllParticipants = %key%.#{Request participants};
string IssueReporter = %key%.#{reporter};

if (contains(AllParticipants, IssueReporter)) {
  %key%.#{Request participants} = arrayDeleteElement(AllParticipants, IssueReporter);
}
```

But it may need some extra rows depending on how/when you want to trigger it. In case you want this script to be triggered by the change of field value reporter or request participants, this should be configured as SIL Listener for "Issue Updated event" with the following script:

```
JFieldChange[] changes = lastIssueChanges(key);

for (JFieldChange c in changes) {
  if (c.field == "customfield_10029" || c.field == "reporter") { // 10029 is Request participants custom field ID


    string[] AllParticipants = %key%.#{Request participants};
    string IssueReporter = %key%.#{reporter};

    if (contains(AllParticipants, IssueReporter)) {
      %key%.#{Request participants} = arrayDeleteElement(AllParticipants, IssueReporter);
    }
  }
}
```

In summary, this script will monitor changes to specific fields in an issue (reporter and requested participants), and if one of those fields is modified and the reporter is listed among the participants, it removes the reporter from the list of participants associated with the issue.

Adding some helpful documentation pages: [Simple Issue Language](https://appfire.atlassian.net/wiki/spaces/PSJC/pages/434798967/Simple+Issue+Language+Reference), [SIL Listener](https://appfire.atlassian.net/wiki/spaces/PSJC/pages/490997990/SIL+Listeners), [Array functions](https://appfire.atlassian.net/wiki/spaces/PSJC/pages/434831645/Array+Functions), [SIL manager](https://appfire.atlassian.net/wiki/spaces/PSJC/pages/490996983/SIL+Manager) .  

Hope it helps!   
Anna

comments: author: Nahuel Logghe
body: Hi Anna,

Thank you very much. The option you are showing definitely seems to be what we need. Unfortunately, I don't think it's worth paying for the plugin's fee at this time since we will only use it for this specific case, which is not very common. Perhaps in the future, if other situations arise where we need to create scripts for our automation rules, we might consider purchasing this plugin. In any case, I am very grateful for the comprehensive solution you have provided.


author: Tansu Akdeniz
body: Hi [@Nahuel Logghe](/t5/user/viewprofilepage/user-id/5433828)

You can try the solution in this thread to remove user from the list.

[Jira Automation remove a user from Approvers](https://community.atlassian.com/t5/Jira-Service-Management/Jira-Automation-remove-a-user-from-Approvers/qaq-p/2157945)

comments: author: Nahuel Logghe
body: Hi Tansu,

Thank you very much for your response. I have reviewed that post and the other links contained within it as well. I have no experience with scripting. I understand that the script removes a fixed element from a list, but I'm wondering if it's possible to adapt that script to meet my specific needs. I need to compare two different values from two fields and conditionally remove one. The example provided doesn't seem to match my case, and I lack the expertise to modify it

Specifically, I need to compare the 'Reporter' field with the 'Request Participants' field, and if the reporter is listed among the Request Participants, then they need to be removed from Request Participants. Perhaps my approach is not correct, and there might be another way to do this?


Tags: automation

cloud

jira-service-management

jira-service-management-cloud