using new and previous custom field values in an automation
Asked by Michael Nassette:

Hi,

I want to execute an automation action based on a custom field value change.  
What I have set up now:  
Trigger:  
When: Value changes for "Field A"

IF  
{{issue.Field A.fieldChange.fromString}} equals X  
AND  
{{issue.Field A.fieldChange.toString}} equals Y  
THEN: Edit issue fields "Field B"

When I edit Field A from X to Y, I expect an action to be executed on Field B.

This action is not happening, when checking the audit log I am getting a "No actions performed" with a "The following issues did not match the condition:".

I do not understand where I am going wrong, though expect it to be something extremely obvious (yet not to me).  
Anybody has any suggestions?


Answers:
author: Michael Nassette
body: So what I settled on is :

```
{{#changelog.Field A}}{{fromString}}{{/changelog.Field A}} equals X
AND
{{#changelog.Field A}}{{toString}}{{/changelog.Field A}} equals Y
```

This is where the plot thickens, and I probably have not been asking the right questions.  
Field A has 6 available value, all starting with a numerical value going from 1 to 6.  

The difference between the first numeric value of X and Y needs to get added to the current value of Field B.  

I think it should be possible to do in 1 line of code (big question mark), but I have clearly bitten off here more than I can chew. I think I understand the logic of how the line should look like, I just can not find out the correct syntax.  
What I am thinking about is the following:

```
{#math}}
{{currentvalue.Field B}} 
+ 
( {{oldvalue.Field A.charAt(0)}} - {{newvalue.Field A.charAt(0)}} ) 
{{/}}
```

Would it be possible at all to use old field values and character stripping in a math formula?

comments: author: Michael Nassette
body: Sorry for whiteboarding here, but I found the solution

When the field value changes, first I create 2 new variables

```
{{oldvalue}} = {{#changelog.Field A}}{{fromString}}{{/changelog.Field A}}

{{newvalue}} = {{#changelog.Field A}}{{toString}}{{/changelog.Field A}}
```

Next I used a THEN component to edit Field B with the following:

```
{{#math}}{{issue.Field B}} + {{oldvalue.charAt(0)}} - {{newvalue.charAt(0)}}{{/}}
```

This does exactly what I need it to do, maybe there is a better way of doing it still, but for now this is sufficient.


author: Boris Zozoulia
body: As per doco, [@Michael Nassette](/t5/user/viewprofilepage/user-id/4795652)

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

The field change trigger exposes {{fieldChange}}variable, which would have the previous and new value for the field in trigger.

So, remove issue.FieldA part in your if condition, and it should work fine

comments: author: Boris Zozoulia
body: Or, at least I assume so, it should work...


author: Anandhi Arumugam
body: Hi [@Michael Nassette](/t5/user/viewprofilepage/user-id/4795652) Could you try something like the following condition based on Smart values?

Advanced Compare condition

Field value = {{#changelog.Field A}}{{fromString}}{{/*Field A*}} equals X

Field value = {{#changelog.Field B}}{{toString}}{{/*Field B*}} equals Y

Hope this helps!


Tags: automation

cloud

jira-cloud

jira-service-management

jira-service-management-cloud