Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Struggling with Automation & Smart Values

Using Automation, I'm trying to do a very simple (seemingly) calculation but not having much success.  Actually - I did get it to work, but still getting the answers to the questions below will greatly increase my understanding of this functionality

Here is what I'm trying to accomplish.  

  • We have a numeric custom field in our issue that is intended to contain the number of hours to complete a task.  The field has no default and therefore if not filled in, it says "None" on the screen and is empty.
  • I want to calculate the cost associated with the task by multiplying the hours times a constant rate.  Ultimately I am going to update another field with the cost, but for now just using the log output function to debug this

Here were my attempts

  • I wanted to do this the hard way first, so I tried using an IF statement using smartvalues.  First I had issues referencing the issue field directly with additions like isempty so I assigned it to a new variable, and that worked fine (???).  So now it was correctly detecting empty vs not empty... And then I assigned the smartvalue below to a new variable...
    • {{#=}} IF({{hours.isEmpty()}} == true, 0, {{hours}} * 53 ) {{/}}
    • I get this errror "Error rendering smart-values when executing this rule: Unknown unary operator '*' at position 22: IF(true == true, 0, * 53 )".  
    • I understand why (because {{hours}} is truly empty), but then how could I ever solve this??  I'm sure there is a simple solution, but I'm coming up empty.
  • Failing the above I decided to try a normal IF ELSE block in the Automation.  Basically I have an if/else block and check if the issue value is empty or not.  If it is empty I assign 0 to a new variable: "hourscost".  In the else block I assign the calculated hours issue value * 53.
    • I have log entries immediately after to make sure the value is in fact stored properly in {{hourscost}}.  Everything is fine there...
    • Falling out of the if/else block my next statement is the final log entry to again display the value of {{hourscost}} but outside of the if/else block the value is blank.  
    • Update: I added an assignment for the same hourscost variable prior to entering the if/else block.  After doing this the value was correctly updated and shows outside the block at the end.  I didn't expect this behavior.  Is the scoping of variables intentionally separate inside the if/else structure.

Bonus question

  • Is there a way to create some type of project level constant (that I can reference from smartvalues) for the rate value above instead of embedding it in the automation?

1 answer

1 accepted

0 votes
Answer accepted
Simeon Ross Atlassian Team Nov 22, 2020

Hey @Chris Grace,

So, your first question, the way to avoid this is to use the default operator, then you don't need an IF. You do it like this:

{{hours|0}}

So that will default to 0 if it has no value :)

So, your second question. IF blocks and related blocks, everything that happens on these is scoped to this block and isn't available on the main line execution, that's why you saw some of these issues.

So, your bonus question. Not easily, but I think it is possible with Entity properties. The issue entity properties are accessible by smart values and we have an action to set them. This action can also set project entity properties. If you can access these via the issue.project.etc then you could have a rule to set the rate on a project and then access it to via the smart values. You'd need to do a bit of experimentation here to see if you can get it working.

Cheers,

Simeon.

Hana Kučerová Community Leader Nov 23, 2020

Hi @Chris Grace ,

maybe alternative suggestion for you bonus question. I would create number custom field for the rate. You can set default value for each project using contexts in this custom field configuration. Then each new issue will be created with the rate specific for the project. You would be able to see, which rate was used in your calculation. If some rate changes during time, you can update the default value, old issues won't be affected (I believe you don't want to change the history).

Thank you very much Simeon and Hana. 

 

Simeon - I will test your suggestions.  Would you please provide a link to the documentation where I can reference your answers.  I really did look and could not find this information.

Hana - thank you.  That's a good idea too.  I need to see if they want to keep the rate value constant in the history or if they are OK with using the "current" rate. 

Thank you both again very much!!

Simeon Ross Atlassian Team Nov 23, 2020

Hi @Chris Grace ,

I don't think that we have documented the question that you had around the scope of variables. I'll look into getting this resolved.

Default values for smart values are in this section. https://support.atlassian.com/jira-software-cloud/docs/what-are-smart-values/#Whataresmartvalues?-Defaultvalues

The entity property details got lost in the docs move too I believe. Our action has a link to the Atlassian docs on them. To view them on an issue, you need to use the REST api.

Eg, XXXXX.atlassian.net/rest/api/2/issue/SP-41/properties

The interesting thing about these is how you access them. This is an example of what you'd see from the above URL:

{
keys: [
{
self: "XXX.atlassian.net/rest/api/2/issue/38007/properties/a-property",
key: "a-property"
}
]
}

To access this in smart values you would do the following:

{{issue.properties."a-property"}}

This is especially important if the property contains periods as they would break our smart values if not in quotes.

I'll let get our docs team know about the omissions and get them onto it!

Cheers,

Simeon.

Thanks again Simeon.  Much appreciated.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD Trial
PERMISSIONS LEVEL
Site Admin
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you