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

Access issue fields during Create

Edited

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.

 

2 answers

1 accepted

2 votes
Answer accepted
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 09, 2020

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:

Capture.PNG

Any idea how to fix that?

This is on Jira 8.7.1 and SR 6.2.1

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 09, 2020

@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.")
}
}
}

@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:

Capture.PNG

That code actually comes straight off of Adaptavist's Examples page:

https://scriptrunner.adaptavist.com/5.5.7/jira/recipes/workflow/validators/validate-attachments-links-in-transition.html

I guess the API was changed since it was written.

Capture.PNG

Like Vikrant Yadav likes this

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.

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 17, 2020

@Jozef Vandenmooter  Great, finally you get the working code. :)

I tested on my side also code was working even after giving error. 

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

Like # people like this
Azfar Masut
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Apr 26, 2022

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]]

Like Vikrant Yadav likes this

Ca be this achieved on Jira Cloud?

Thank you

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.5.1
TAGS
AUG Leaders

Atlassian Community Events