How to return original number value of custom field and the New Value
Asked by Jocelyn Aquilina:

Hi everyone,

I am trying to automate a part where I have a Parent ticket linked to several child tickets. Now what I want is basically to reflect the number of impacted transactions from the child tickets and the total would add up to the parent. My problem is not knowing how to reflect this whenever a user amends the number within a child ticket. I tried using changelog but no success.

E.g. 1 Parent ticket linked to 1 child ticket, child ticket has 1000 impacted transactions. Therefore Parent also has 1000 transactions. User changes from 1000 to 800, then I would expect the Parent to be changed also.

Tried the following equation basically:

Simple terms: Parent custom field value subtracted from the trigger issue custom field value and added with the new value of the same trigger issue.

Equation attempted which did not work:

{{issue. customfield_18480}} -{{triggerIssue.changelog.Numbers.customfield_18480.fromstring}} + {{triggerIssue.changelog.Numbers.customfield_18480.tostring}}

Would appreciate if someone knows how to work through it or maybe find another way...


Answers:
author: Bill Sheboy
body: Hi [@Jocelyn Aquilina](/t5/user/viewprofilepage/user-id/5069338) -- Welcome to the Atlassian Community!

I noticed a few things with your expression: it has extra spaces around the smart values, the [changelog syntax](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/#--changelog--) is incorrect, and it is missing the [math operator syntax](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/).

Please try this instead, assuming your custom field is a number type:

{{#=}}{{issue.customfield_18480}} - {{#changelog.customfield_18480}}{{fromString.asNumber}}{{/}} + {{#changelog.customfield_18480}}{{toString.asNumber}}{{/}} {{/}}

The changelog smart value is relative to the trigger issue, and so there is no need to add the extra prefix.

Kind regards,  
Bill

comments: author: Jocelyn Aquilina
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) !  

I just tested it out, and it seemed to not work again.. Checked the audit log and the following screenshot appeared..

![Capture.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/223930i2BB55D44505BB062/image-size/large?v=v2&px=999 "Capture.PNG")


author: Bill Sheboy
body: Hi, Jocelyn.

Would you please post an image of your complete rule, including the details of the smart value expression, and the image of the audit log showing all the steps from that rule run? That may provide more context to explain what is happening.

Thanks!


author: Jocelyn Aquilina
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) !

Please find the image of the audit log showing that rule was executed with some errors. Unfortunately I needed to hide the project behind the ticket numbers...

I will explain in short the rule..

1) Trigger for the rule applies when: Issue is created/edited/transitioned/assigned

2) If Condition: Epic that will be linked to issue exists

3) Branch Rule: For the Epic (Parent)

4) Edit the issue field for the Epic.

![Capture1.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/224134iDB2D44AF0C68EBA8/image-size/large?v=v2&px=999 "Capture1.PNG")![Capture.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/224135i84C4D565F48744BB/image-size/large?v=v2&px=999 "Capture.PNG")


author: Bill Sheboy
body: Thanks for that information, [@Jocelyn Aquilina](/t5/user/viewprofilepage/user-id/5069338)

What is the type of your custom field: text, number, single-select, etc.?

And, let's add some diagnostic checks to help see what is happening...**After your trigger**, please adding three writes to the audit log using Log Action containing each of these values. Then run the rule and post what the audit log shows:

```
Custom field is: {{issue.customfield_18480}}
```

```
The from value is: {{#changelog.customfield_18480}}{{fromString.asNumber}}{{/}}
```

```
The to value is: {{#changelog.customfield_18480}}{{toString.asNumber}}{{/}}
```


author: Jocelyn Aquilina
body: Hello [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) !  

This custom field is a simple Number Field. I will try this suggestion soon as I am very new at this! Thanks!


author: Jocelyn Aquilina
body: Would you be able to show me with screenshots on how to insert these into the audit logs?


author: Bill Sheboy
body: After the trigger in your rule, select Add Component, and then select the one for Log Action, such as below:

![Capture.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/224490iF898145260ABD347/image-size/large?v=v2&px=999 "Capture.PNG")

Select Save, and do the same thing for the other two smart value entries.

Then run your rule, observe the audit log details, and post an image of what you observe.


author: Jocelyn Aquilina
body: Hello [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) !  

Thank you for explaining, the logging action worked. Please find the screenshot as requested. It seems the old and new values of the trigger ticket are not being picked up..

![Log Action.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/224551i247E623A7B0DAC63/image-size/large?v=v2&px=999 "Log Action.PNG")


author: Jocelyn Aquilina
body: By the way, I changed the value from 100 to 200 in the trigger issue.


author: Bill Sheboy
body: Just to clarify, are you saying your field edit changed the field from 100 to 200, and the log of the value instead shows 250.0?

In that case, I suspect you have the wrong field's custom field id (or that it is a calculated field from an addon app and so may not be supported).

Let's try this, based on this how-to article to identify your smart value: <https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/>

1. Identify the issue key for that one you just edited. For example *MYPROJECT*-5469
2. Identify the url for your Jira site, *yourJiraUrl*
3. In a new browser tab, enter a url to query the issue's fields: https://*yourJiraUrl* /rest/api/2/issue/*MYPROJECT*-5469?expand=names
4. On the page, search for the Name of your field, and note the custom field id. That is the one to use in the rule
5. If the field is not present, then your field is not supported in automation rules


author: Jocelyn Aquilina
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) !

Custom field number is definitely correct. With regards to the number part, I edited the number from 100 to 200 on the trigger issue and the 250 is the original number left on the Epic ticket. What this means I was supposed to be seeing an increase of 100 in the Epic, taking the total to 350.

Could it be that we need to refer to the trigger issue's custom field within the "The from value" and the "The to value" within the equations you provided?


author: Bill Sheboy
body: The changelog smart values only refer to the changes in the trigger issue, so no rule confusion there.

Would you please post an image your current, entire rule? That may provide context in case we are missing something about the rule structure. Thanks!


author: Jocelyn Aquilina
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) !  

The entire rule is here:  
![Capture.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/223798iAAC109865245365B/image-size/large?v=v2&px=999 "Capture.PNG")

The "When" part is basically: the following.  

![Field Value.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/225057i693EF24DC170E50B/image-size/large?v=v2&px=999 "Field Value.PNG")

The rest of the rule is only a condition that if the Epic simply exists and the Edit part for now is the latest one that you suggested to insert as the equation before the logging action part.


author: Bill Sheboy
body: In your screen image of the Edit Action, the smart value has extra spaces and some extra syntax.

For example, you have:

```
{{issue. customfield_18480}}
```

There should not be a space after issue.

And I see

```
{{triggerIssue.changelog.Numbers...
```

As I noted earlier, the changelog smart value can only apply the trigger issue, and so you do not need that in the expression. Instead use this:

```
{{#changelog.customfield_18480}}{{fromString.asNumber}}{{/}}
```

If that does not help, I suggest working with your site admin to submit a ticket to Atlassian Support at the link below. They may be able to see something we are missing to make this work. <https://support.atlassian.com/contact/#/>


author: Jocelyn Aquilina
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

Thank you for your help, will keep trying and take it up with my site admin maybe some part of my project is "off".

Best regards,

Jocelyn


author: Jocelyn Aquilina
body: Forgot to mention. JIRA version is v8.22.6

![Capture.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/223798iAAC109865245365B/image-size/large?v=v2&px=999 "Capture.PNG")