Need help to execute Groovy Script in Jira 3.13

Hello Team,

I am trying to copy the Asset Class custom field's value into Security Level system field by using following script.

Script is running sucessfully but value is not getting coppied. I am able to use the similar script for the another project while creating the issue. Not sure where I am going wrong here.

Please help me out to correct the scrpit or to get the results.

try {

ComponentManager componentManager = ComponentManager.getInstance()

CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

IssueSecurityLevelManager securityLevelManager = componentManager.getComponentInstanceOfType(com.atlassian.jira.issue.security.IssueSecurityLevelManager)

IssueSecuritySchemeManager issueSecuritySchemeManager = ManagerFactory.getIssueSecuritySchemeManager()

IssueSecurityLevelManager issueSecurityLevelManager = ManagerFactory.getIssueSecurityLevelManager()

GenericValue srcProjectGV = issue.getProject()

log.debug(srcProjectGV)

def issueSecurityScheme = issueSecuritySchemeManager.getSchemes(srcProjectGV).size() == 0 ? null : issueSecuritySchemeManager.getSchemes(srcProjectGV)[0]

User currentUser = componentManager.getJiraAuthenticationContext().getUser()

def sourceFieldName = "customfield_10130"

CustomField cf = customFieldManager.getCustomFieldObjectByName("Asset Class")

CustomFieldParams sourceFieldVal = issue.getCustomFieldValue(cf) as CustomFieldParams

//CustomField cfBusiness = customFieldManager.getCustomFieldObjectByName("Catch Business Value")

if (sourceFieldVal) {

Collection values = sourceFieldVal.getAllValues()

def business = values[0]

log.debug("business: '$business'")

def level = values[0]

log.debug("level: '$level'")

//def business= sourceFieldVal.getFirstValueForNullKey()

//def level = sourceFieldVal.getFirstValueForKey("1")

//set the text field

cfBusiness.createValue(issue, business.toString())

//set security level

def secLevelGvList = issueSecurityLevelManager.getUsersSecurityLevels(issue.getGenericValue(), currentUser)

def secLevelGv = secLevelGvList.find ({it.get("name") == "$level"})

log.debug("secLevelGv: $secLevelGv")

if (secLevelGv) {

log.debug ("Set ${issue.getKey()} to $level")

issue.setSecurityLevel (secLevelGv)

}

issue.store()

}

else {

log.debug("Custom field not present on this issue")

}

log.debug("done")

} catch (Exception e) {

log.error("oops", e)

}

Let me know incase you need any further details.

Regards,

Arpita

1 answer

This widget could not be displayed.

Can you use the CODE formatting on the toolbar, it's not possible to read that.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted 8 hours ago in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

21 views 0 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you