I want to do something that goes "hey, if I have no worklog entries, print a message" in a web request in Jira Automation.
For most fields I have no issues going {{if(exists(issue.assignee),"Exists","Missing")}} and having it work.
However for worklog, it looks like worklogs are setup as such per the API response for a ticket:
Worklogs containing more data when work has been logged.
Now, I cant seem to just output {{issue.worklog.total}} even when Total comes back with a value of 1 in the API output for the ticket.
Looking at the documentation here: https://confluence.atlassian.com/automation/jira-smart-values-issues-993924860.html
I would expect that I could use {{issue.worklog.timeSpentSeconds}} to get a value to output, and I can.
My problem is if I want to do {{if(exists(issue.worklog.timeSpentSeconds)),"True","False"}} it always returns false even if I have {{issue.worklog.timeSpentSeconds}} right after it outputting a number.
Maybe exists doesnt work with the data format? I tried {{if(issue.worklog.timeSpentSeconds.isEmpty(),"True","False")}} and this also does not work.
I also tried {{#=}}{{issue.worklog.timeSpentSeconds}} <= 0 {{/}} and this errors out if there is no value for timespent in seconds and it returns true if there is time spent. I am also not quite sure how to nest a math expression like this into an if statement to get the exact output I need.
Hi @Travis -- Welcome to the Atlassian Community!
I am using Jira Cloud, and this worked for me:
{{if(issue.worklog.timeSpentSeconds.sum.gt(0),"has logs", "does not have logs")}}
I believe those smart values are common between Cloud and Server, so give it a try.
Kind regards,
Bill
This worked great! I have no idea what the .gt(0) is though, is this documented somewhere?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome; I am glad to learn that helped, and...sorry I did not explain that one better!
Here goes, and please let me know if I miss anything:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your situation involves a few nuances with Jira Automation and handling complex JSON structures, particularly when working with conditional checks and smart values. Given what you've described, it seems the primary challenge is accurately determining whether worklog entries exist and then conditionally outputting a message based on that condition.
The exists function and trying to access issue.worklog.timeSpentSeconds directly can be problematic for your use case due to how worklog data is structured and how smart values are evaluated in Jira Automation. Since timeSpentSeconds may not be directly accessible as a cumulative value across all worklogs at the issue.worklog level, this could be why your conditional checks are failing.
A workaround involves focusing on the issue.worklog.total value you mentioned. This value should accurately reflect whether any worklog entries exist. However, you've noted difficulty in outputting {{issue.worklog.total}} directly, which suggests a peculiarity in how Jira Automation handles nested JSON objects for smart values.
Here's a strategy to achieve your goal, based on the available documentation and common practices with Jira Automation smart values:
Strategy for Conditional Check Based on Worklog Entries
Directly Reference worklog.total: Since accessing the total count of worklogs is a reliable way to check for entries, focus on this value. However, since you're having trouble directly referencing it, consider using a workaround with advanced field editing in the automation rule to set a custom field or variable based on this value, which can then be used in your condition. This step may involve using a webhook or a "Log action" to first capture the worklog.total value if direct referencing continues to fail.
Use Advanced Comparisons: If direct smart value referencing for worklog.total isn't working as expected, use Jira Automation's ability to execute more complex logic, potentially through webhook payloads or additional JSON parsing steps within your rule to properly evaluate this value.
Custom JavaScript in Webhook: Consider using the "Send web request" action to send the issue data to a custom endpoint, where you can use JavaScript to evaluate the worklog.total value and return a custom response based on whether worklogs exist. This approach is more complex and requires an external service but offers full control over the logic.
Revisit the Advanced Branching or Conditions: Since {{#=}}{{issue.worklog.timeSpentSeconds}} <= 0 {{/}} leads to errors when no value is present, and embedding math expressions directly in if statements isn't straightforward, use advanced branching with a predefined variable or a custom field set to worklog.total as a workaround.
Feedback to Atlassian: Given the challenges with exists and direct property checks for worklog.timeSpentSeconds, consider providing feedback to Atlassian. There may be limitations or bugs in how smart values are evaluated for nested objects, and your use case could highlight an area for improvement in their documentation or functionality.
Example Pseudo-Logic
I suggest a pseudo-logic approach based on the above strategies:
Step 1: Attempt to capture worklog.total in a custom field or through a log action.
Step 2: Use this captured value in a conditional statement, such as {{if(issue.fields.customFieldForWorklogTotal > 0, "Worklogs exist", "No worklogs")}}.
This approach requires adapting based on the specific capabilities and limitations of your Jira Cloud environment and may involve creative use of the available automation actions, conditions, and third-party integrations
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.