Automation creation for "Project Start/ Target" custom date fields for -#days
Asked by Sahar Qarem:

Hello,

Need to create a jira automation to send a scheduled email of all the ideas that have a project target in set number of days, but since it's not a jira field I'm only able to search for a specific date not if "x number of days left.

Any idea how?


Answers:
author: Nick H
body: Hi [@Sahar Qarem](/t5/user/viewprofilepage/user-id/5308011) .

Important to note [Jira dates](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/) follow a specific date (and time) formatting like:

```
"YYYY-MM-DD"
```

JPD dates follow a range formatting like:

```
"{\"start\":\"YYYY-MM-DD\",\"end\":\"YYYY-MM-DD\"}"
```

Because of the difference - JPD date-fields are not fully supported with automations, and also do not have the same filtering / JQL capabilities like Jira date-fields.

Having said that, I think your use case may still be possible if we manipulate the JPD date-field through [smart values](https://support.atlassian.com/cloud-automation/docs/smart-values-in-jira-automation/), and compare it to a date or another field. Below is an example of this.

![targetdate1.jpeg](https://community.atlassian.com/t5/image/serverpage/image-id/334753iA690A63859077412/image-size/large?v=v2&px=999 "targetdate1.jpeg")

1) WHEN: Scheduled (select when this automation should be scheduled to run)

2) THEN: Create variable

* Variable name = TargetDate (or anything you like)
* Smart value =

```
{{issue.customfield_XXXXX.substringBetween("\"start\":\"","\",\"end\"")}}
```

* \^ customfield_XXXXX would be the [custom ID](https://confluence.atlassian.com/jirakb/how-to-find-any-custom-field-s-ids-744522503.html) of your JPD date-field

\*3 / 4) These steps can be disregarded, and were simply used for [logging](https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Log-action) purposes to troubleshoot and debug throughout testing

5) IF: {{smart values}} condition (aka "Compare two values")

* First value = {{TargetDate}}
  * \^ This would be the variable configured in step 2
* Condition = equals
* Second value = {{now.plusDays(5).jiraDate}}

6) THEN: Send Slack message (or email user(s) / preform some other action)

Step 2 converts my JPD Project target field from a range, into a variable with the formatting of yyyy-mm-dd. This is done using [string processing](https://support.atlassian.com/jira-service-management-cloud/docs/string-processing-methods/).

Step 5 then compares the variable to the present date + 5 days from now (future date so to speak), and if these two dates match - the automation sends a message to Slack.

Here is the Audit log tab of this automation through some testing:

![targetdate2.jpeg](https://community.atlassian.com/t5/image/serverpage/image-id/334754i383F7DDC67237712/image-size/large?v=v2&px=999 "targetdate2.jpeg")

I'm not sure this is the "perfect" way to do this, but I hope it helps and can reference when configuring your automation!

comments: author: Sahar Qarem
body: Hi Nick,

I've tried it, and it's not working. I've used the log and it shows as attached.

maybe the smart value format is missing something?

{{issue.customfield_10152.substringBetween("\\"start\\":\\"","\\",\\"end\\"")}}

![Screenshot 2024-07-11 at 17.41.45.png](https://community.atlassian.com/t5/image/serverpage/image-id/335005iE7774658A3D6D2FE/image-size/large?v=v2&px=999 "Screenshot 2024-07-11 at 17.41.45.png")![Screenshot 2024-07-11 at 17.38.24.png](https://community.atlassian.com/t5/image/serverpage/image-id/335004i1F0F366D17802C03/image-size/large?v=v2&px=999 "Screenshot 2024-07-11 at 17.38.24.png")


author: ALAA EDDINE ROUCADI
body: Hi [@Sahar Qarem](/t5/user/viewprofilepage/user-id/5308011) ,

It would be very helpful if you could post the log action result of the custom field "{{issue.customfield_10152}}". This will allow us to see the value structure. The next step would be to process this value using automation smart values to extract the information you need.

Regards,


author: Sahar Qarem
body: Hi Alaa,

I've logged it and getting the same and Project Target above, (no result, empty)

I've executed the JQL below:

```
Project=XM AND "project target"~"2024-07-12" ORDER BY cf[10152] DESC, Created DESC
```

Where, "Project Target" is the custom field used in "order by" as well.

How can i search JQL using smart values?


author: ALAA EDDINE ROUCADI
body: Hi [@Sahar Qarem](/t5/user/viewprofilepage/user-id/5308011) ,

One thing to **verify** is the **Scheduled trigger** of your automation. You need to use a ++JQL search++ to define the set of issues that the rest of the automation will run on by checking "++*Run a JQL search and execute actions for each issue in the query*++".

This could be a JQL search that filters and returns only the issues corresponding to all the ideas that have a project target. You can validate the search query without running the automation, check how many issues are returned, and even click on the link to display the search results.

Regards,


author: Sahar Qarem
body: Hi [@ALAA EDDINE ROUCADI](/t5/user/viewprofilepage/user-id/5527514) ,

I've executed the JQL below:

```
Project=XM AND "project target"~"2024-07-12" ORDER BY cf[10152] DESC, Created DESC
```

Where, "Project Target" is the custom field used in "order by" as well.

How can i search JQL using smart values?


author: ALAA EDDINE ROUCADI
body: Hi [@Sahar Qarem](/t5/user/viewprofilepage/user-id/5308011) ,

Unfortunately, as far as I know, in JPD context, the project start/target date is a relatively new and complex structure that is not supported by JQL (including using smart values)

One approach could be to filter, at the **Scheduled trigger** level, for ideas with a target date using a query like:
>
> ```
> Project=XM AND 'project target' is not empty ORDER BY cf[10152] DESC, Created DESC.
> ```

Then, follow the steps described by [@Nick H](/t5/user/viewprofilepage/user-id/2540930) [HERE](https://community.atlassian.com/t5/Jira-Product-Discovery-questions/Re-Automation-creation-for-quot-Project-Start-Target-quot-custo/qaq-p/2750757/comment-id/4971#M4971). For each returned issue, the automation will:

1. *Extract the target date* from your custom field. Example of **LOG** **expression**

   ```
   Start date: {{issue.customfield_10152.match("start\":\"([0-9-]+)\"").first}}, End date: {{issue.customfield_10152.match("end\":\"([0-9-]+)\"").first}}
   ```

2. Run it through a *smart values comparison*,
3. *Send the notification* if the condition is met.

***PS:***There will be one notification sent per issue fulfilling the condition.


author: Sahar Qarem
body: Hi [@ALAA EDDINE ROUCADI](/t5/user/viewprofilepage/user-id/5527514) ,

The log expression is still coming back empty for some reason, but adding the JQL query the at the "scheduled" trigger worked and the rule is executing correctly now.

Thank you!


author: Nick H
body: Hi Community,

We were able to get this resolved through a support ticket using an automation like the one below - which can send a daily email of all ideas if their JPD date-field matches the present day:

![sched1.jpeg](https://community.atlassian.com/t5/image/serverpage/image-id/337337i666565AC5E0FD998/image-size/large?v=v2&px=999 "sched1.jpeg")

1) WHEN: Select schedule for automation to run

2) THEN: Lookup issues - JQL:

```
project = XYZ AND cf[00000] ~ "\"end\":\"{{now.jiraDate}}\""
```

\^ cf\[00000\] is the JPD date-field's ID. Can find this using this doc:

* [How to find any custom field's IDs](https://confluence.atlassian.com/jirakb/how-to-find-any-custom-field-s-ids-744522503.html)

3) AND THEN: Send email - which uses the [Lookup issues](https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Lookup-issues) from previous step to list all ideas in email body using this:
>
> ```
> {{#lookupIssues}}* {{key}}, {{summary}} - {{url}}{{/}}
> ```


author: Sahar Qarem
body: deleted