Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Field editing based on reporter (script behaviour)

valeria cruz
Contributor
April 26, 2022

Hi! I need to build a behavior script for editing the epic link field based on the reporter. I'm using a server-side script function, but the script doesn't work when the reporter is a different user.
Follow my script



import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor

def reporterfield = getFieldByName("reporter")
def cfEpicLink = customFieldManager.getCustomFieldObjectsByName("Epic Link")


if(reporterfield != ("rocket")){
getFieldByName("Epic Link").setReadOnly(false);
}

else
reporterfield == ("rocket")
getFieldByName("Epic Link").setReadOnly(true)

1 answer

0 votes
Ilya Stekolnikov
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.
April 26, 2022

try this 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue


def cfEpicLink = customFieldManager.getCustomFieldObjectsByName("Epic Link")

def userManager = ComponentAccessor.getUserManager()

def reporterField = getFieldById("reporter")
def reporterValue = reporterField.getValue()
def reporterUser = userManager.getUserByName(reporterValue.toString())

 

if(reporterUser != ("rocket")){
getFieldByName("Epic Link").setReadOnly(false);
}

else
reporterUser == ("rocket")
getFieldByName("Epic Link").setReadOnly(true)

Suggest an answer

Log in or Sign up to answer