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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,551,931
Community Members
 
Community Events
184
Community Groups

Scriptrunner for getting the current key on runtime in production environment

The new JIRA has been installed and i am facing the issue in script-runner. I m searching for 4 days.

The two point is provided below which i need to fix:

1. I am unable to restrict for update the value of an issue at the time of issue update event. I had created a script on script listener.

2. Instead of hard coded value for key, i want to use dynamic code on script-runner. Means if the ticket is sub-task issue and project will be the same then the below script will execute.

Here the script is provided below and the requirement is duedate value for Task IssueType should be greater than the Duedate value for n number of subtask IssueType :

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.customisers.ContextBaseScript
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.opensymphony.workflow.InvalidInputException

//

@BaseScript ContextBaseScript script

Issue issue = getIssueOrDefault("TEST-258") // Hard coded issue-key defined

if(issue.parentObject.dueDate.compareTo(issue.getDueDate()) >= 0)
{
UserMessageUtil.success("Due Date Success"+issue.dueDate)
log.debug(issue.getDueDate())
}
else
{
UserMessageUtil.success('Please enter the Subtask duedate that is less than Parent-Task Due-Date ')
//throw new InvalidInputException("Input not valid")
}

The problem is that when the condition fails then the date will be update first and next the pop up alert is raised which i mentioned in the code but I am unable to restrict the due date update. Also recommend us for second point on run-time environment(on production).Due_Date_code_Listener.jpgTEST-247.jpgTEST-258.jpg

1 answer

0 votes
brbojorque
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 06, 2020 • edited

Hi @Kalyan Kumar Das ,

So your requirement is to prevent the Subtask from being created/saved if the Due Date of the Sub-task is greater than the Due Date of parent task?

Then you should use Behaviour to validate it from being created/saved in the first place.

Issue Updated event in the listener assumes that the value is already saved as opposed to preventing it from being saved.

Nic Brough -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.
Jan 07, 2020

You could also use a validator on the create (sub-task) transition.  This might be better than a Behaviour because it will work for REST and other automations, can't be bypassed by javascript tweaks, and it will take the person back to the "create issue" screen with all their data intact and a warning on the relevant field, with a lot less code!

@Nic Brough -Adaptavist-: I am not getting your point. Request you to elaborate the same.

Because i had already used the validator on the create(sub-task) transition. And it is working fine at the time of creating the issue but it is not working at the time of issue update event.

May be i missed something in the code?   

Request you to update on that. In case of any required from my end, please let me know.

Nic Brough -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.
Jan 24, 2020

But the code you've given us

  • Overrides the current issue object with another one
  • Looks at the parent of the fixed issue (we don't know if it even has one)
  • Compares the due date of the parent of the fixed issue with a date in 1970

So it's always going to pass validation

Could you give us the actual code?

And also bear in mind that a validator only executes on the transition it is on.  Editing an issue is not a transition.

But in workflow, there is no any transition defined. I had created a script listener in which i had defined in the project name and event(Issue Updated Event). 

For reference, the screenshot is already attached on that above.

 

Nic Brough -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.
Jan 27, 2020

A listener has no validators itself, it runs when an event is detected.  It is up to you to put code in to detect if you want to do things selectively.

Listeners do not have any UI interaction.  They can't - they're not being run on the UI, they run in the background when events happen.

The code you've shown us is a validator, not a listener.

I think we need to take a step back.  Forget the code you have, and tell us what you're actually trying to achieve?  What do you want the user to experience?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events