How to fetch and compare previous value and new value of Due Date field

Anupam Sinha January 18, 2021

Hi everyone, I am new to Jira and stuck with a task

I need to read previously entered value and newly/update  entered value in Due Date and compare both of them and

1. Ask user to enter the reason of change due date in text box

2. Send alert notification to PM on Due Date Change  as user updates the issue in JIRA.

 

Any help would be greatly appreciated.  

3 answers

1 accepted

0 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2021

Hi Anupam,

I can confirm that it is possible to achieve your requirement with ScriptRunner for Jira Cloud by creating a Script Listener that is configured on the Issue Updated event. 

The script for the listener would then be able to get the changelog property which contains details of what fields changed when the issue was updated.

You would then be able to check against this property if the Due Date field changed and if it did to save the old and new values for these fields to variables in your script.

You would then be able to call to the Send a notification for an issue API which Atlassian provides in order to send a notification explaining how the Due Date field changed.

I can confirm we have an example script located in the documentation page located here which shows how to check the changelog property and to send a notification when the priority on an issue changes.

You will be able to take this script and use it as a reference guide to help you to create the script that you require to achieve your requirements.

As for your requirement of checking what the user enters on the screen then you can do this using a Workflow Validator  and this page gives some examples as well explains how to add a new validator to your workflow.

Also, we have a Knowledge Base Article here which explains the strategy that should be used to determine how to create the validator expression which you require but it would be similar to the expressions other users have given above.

I hope this information helps.

Regards,

Kristian

Anupam Sinha February 7, 2021

Thank you so much Kristian for kind help and useful tips. 

1 vote
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2021

Hi @Anupam Sinha ,

To force the user to enter a comment describing the reason for the Due Date change, you can add a JMWE Build-your-own Validator with the following script:

originalIssue.dueDate == issue.dueDate || issue.comments.some(it => !it.id)

 And you'll enter an error message like: "You must describe, in a comment, the reason for te Due Date change"

As for notifying the PM, you could use a JMWE Email Issue post-function, configuring it to notify the members of the "PM" project role, and using Conditional Execution to send the email only if the Due Date field was modifying during the transition. This can be done using this conditional execution script:

{%set lastDueDateChange = issue | fieldHistory( "duedate" ) | last %}
{{ not lastDueDateChange or (lastDueDateChange.date | date | date("diff", nowObj, "s" ) > -10)}}
Anupam Sinha January 19, 2021

Thank you David for looking into it. Currently, I am trying to automate the workflow with Scriptrunner. I will also try with JMWE 

0 votes
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2021

Hi Anupam - Welcome to the Atlassian Community!

The only think I know to do in this scenario is to create another custom field and set it equal to the value of the Due Date when it is created or first populated. Then when it is changed, you can compare the new Due Date to the value in the custom field using JMWE or ScriptRunner.

Anupam Sinha January 19, 2021

Thank you John. Constraint is : Client does not want to add another custom field. With the additional custom field  it is bit challenging. 

Suggest an answer

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

Atlassian Community Events