You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
I'm trying to write a ScriptRunner Validator script that throws an error when the user did not link the issue (Defect) to a parent (Story) during the Create action.
I can't find a way to access the fields of the issue because at that point it's not stored in the database yet. How do I do that?
I know it can be done using a Behaviour, but in this case I'd like to use a Validator.
Hi @Vikrant Yadav thanks - I actually did look at that one, but I couldn't get it to work because one of the methods gives me an error:
Any idea how to fix that?
This is on Jira 8.7.1 and SR 6.2.1
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jozef Vandenmooter have you tried this one also :-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.fields.IssueLinksSystemField
import com.opensymphony.workflow.InvalidInputException
import webwork.action.ActionContext
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.link.IssueLink
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("")
def fieldManager = ComponentAccessor.getFieldManager()
def linksSystemField = fieldManager.getField("issuelinks") as IssueLinksSystemField
def request = ActionContext.getRequest()
if (request) {
def params = request.getParameterMap()
def issueLinkingValue = linksSystemField.getRelevantParams(params) as IssueLinksSystemField.IssueLinkingValue
for ( link in issueLinkingValue.getLinkedIssues() ){
def object=ComponentAccessor.getIssueManager().getIssueObject(link)
if(object.getIssueType().toString() != 'Initiative'){
throw new InvalidInputException(IssueFieldConstants.ISSUE_LINKS,
"Note: You must link this Deployment Request to a Initiative.")
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Vikrant Yadav, that one gives me the same error. Also, there's no need to define the issue, right? It gives me a warning issue is already a binding variable:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That code actually comes straight off of Adaptavist's Examples page:
I guess the API was changed since it was written.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Turns out this is not a real error. It's incorrectly reported by the Static Type Checker as an error and can be ignored. The code works fine.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jozef Vandenmooter Great, finally you get the working code. :)
I tested on my side also code was working even after giving error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi from the future
Use
requestMap = ActionContext.getRequest()?.getParameterMap()
def blockingIsSet =
requestMap?.get('issuelinks-linktype') == ['blocks'] &&
requestMap?.get('issuelinks-issues')?.size() > 0
instead
No need to import a bunch of unrelated stuff
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To also add, you may use the following :
if (object.getIssueType().name.toString() != 'Bug')
Following are the full object you can utilize:
IssueConstantImpl[[GenericEntity:IssueType][sequence,null][name,Bug][iconurl,/secure/viewavatar?size=xsmall&avatarId=93577&avatarType=issuetype][description,null][style,null][id,31500][avatar,93577]]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.