Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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.

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.

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.

 

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
Community showcase
Published in Marketplace Apps & Integrations

Jira issue check and more advanced commit verifications for Bitbucket DC

Pre-receive hooks that verify the Git commit message, the modified files, and implement similar code change controls used to be requirements of large enterprises working in regulated industries only....

31 views 0 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you