Automation help understanding and setting due date in new ticket triggered from another

Glenn A
Contributor
October 11, 2024

Hey buddies!

I need help sorting out setting the due date of a new issue created by an automation triggered by another's status change. 

  • trigger issue in JPD project A has a custom field (cf[12345]) with the project due date and looks like this in a JQL filter:
    • {"start":"2025-12-31","end":"2025-12-31"}
    • QUESTION: what does this date look like this?
  • I want the new issue in Jira project B to take the date from this field and add it to (default) 'due'

At the moment, I set the Due date in the automation's Then block that creates the issue and have this for the date: {{customfield_12345.jiraDate}} and is succeeds, but the due date doesn't have anything in it.

Digging deeper (API query against Project A JPD trigger issue, I see that the 'source' date field schema looks like this:

{ "type": "string", "custom": "jira.polaris:interval", "customId": 12345 }

and the created issue in Jira Project B's schema is:

{ "type": "date", "system": "duedate" }

How do I convert that "end" date in A which appears to be a string to a date in project B's issue?

Thanks!!! 

3 answers

1 accepted

0 votes
Answer accepted
Glenn A
Contributor
October 15, 2024

OK, what ended up working, regardless of understanding why it's not doing what it should, is the following:

{{issue.customfield_12345.substring(29,39)}}

knowing the date is always structured as 4d-2d-2d then the substring location is always the same.

Pragmatism at its finest LOL

Thanks for the assists!

0 votes
Eduardo
Contributor
October 12, 2024

The issue you're facing is related to how Jira handles custom fields and the need to convert a string date (from a custom field in Project A) into a valid date format for the Due Date field in Project B. Specifically, your custom field in Project A is using a JSON format, which is stored as a string, and the Due Date field in Project B expects a proper date format.

Here's a breakdown of how you can resolve this:

1. Understanding the Custom Field Format:

  • The custom field in Project A (customfield_12345) appears to hold a date range in the form of:
    {
      "start": "2025-12-31",
      "end": "2025-12-31"
    }
    
  • This is stored as a string in the format yyyy-MM-dd but within a JSON object. You are interested in the "end" date, which you need to extract and convert to a valid Jira date.

2. Extracting the "end" Date:

  • Since the value is stored as a string in JSON format, you need to access the "end" field directly using smart values and then convert it into a Jira-compatible date.
  • To extract the end date from the custom field, use:
    {{customfield_12345.end}}

3. Converting the Extracted String to a Jira Date Format:

  • Once you have the "end" date as a string, you can convert it to a Jira-compatible date format. Fortunately, Jira Automation supports date conversion using .jiraDate or .toDate.
  • Use the .toDate function to convert the string into a date that Jira can understand:
    {{customfield_12345.end.toDate}}

4. Setting the Due Date in Project B:

  • Now that you have the end date from Project A in the correct format, you can use it to set the Due Date for the newly created issue in Project B.
  • In the Then block of your automation (the part where you create the new issue), set the Due Date field with this smart value:
    {{customfield_12345.end.toDate}}

Full Automation Setup Example:

  1. Trigger: Status change in Project A (JPD Project).
  2. Condition: Ensure the custom field cf[12345] has a value.
  3. Action (Create issue in Project B): When creating the new issue, in the Set Fields section for Due Date, use the following smart value:
    {{customfield_12345.end.toDate}}

5. Additional Debugging with Logs:

If it's still not working as expected, add a Log action before the issue creation to see what value is being returned:

Logging: {{customfield_12345.end}} and {{customfield_12345.end.toDate}}

This will help confirm that the date is being extracted and converted correctly before you use it in your automation.

  • Use {{customfield_12345.end.toDate}} to convert the string date to a proper Jira date.
  • Ensure you extract the "end" value directly and convert it using .toDate before applying it to the Due Date field in Project B.

This approach should allow the automation to correctly set the Due Date in Project B based on the date range stored in the custom field of Project A.

Glenn A
Contributor
October 15, 2024

@Eduardo 

Thanks for the well written solution, but I had already tried this and it didn't work. I don't think the text is being properly converted to JSON because I get nulls. More specifically, the result of the Logging line are:

"Logging: and "

Where I am making painful traction is on crafting a regex to parse the text string :(

 

0 votes
Marcelo Ulloa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 11, 2024

Hello

To set the "end" date from a custom interval field in Project A as the due date in Project B:

  1. Use the "end" value because the field in Project A is an interval containing both a start and an end date. The end date indicates the finish point of the interval, which is why it's needed.

  2. Try to automatically convert this end date to the Jira date format with:

{{issue.customfield_12345.end.jiraDate}} 

       3. If this doesn’t work, explicitly format the date like this: 

{{issue.customfield_12345.end.format("yyyy-MM-dd")}}

 

I hope this helps, if so, mark the answer as correct. 

Glenn A
Contributor
October 15, 2024

@Marcelo Ulloa 

Thanks for the suggestion, but this didn't work. I don't think the text string is being recognized as proper JSON... I can parse substrings to extract a date using regex but specifying start or end returns null.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events