Set Custom Encrypted Field Value using Scriptrunner

Alex Guzman
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 4, 2024

According to: https://docs.adaptavist.com/e4j/latest/usage/api-methods

I should be able to set a value into an empty encrypted field but I am getting an error on cfList.updateValue and I am not sure why. A little more context, we have some fields that are not encrypted currently but because they hold employee PI we want to hide them from unauthorized users so this script will be used to copy the unencrypted value into the encrypted field then the old fields will be removed.

Code:

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.event.type.EventDispatchOption
import groovy.json.JsonSlurper
import org.apache.log4j.Level
import org.apache.log4j.Logger

def log = Logger.getLogger("com.onresolve.jira.groovy")
log.setLevel(Level.INFO)

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def commentManager = ComponentAccessor.getCommentManager()
def attachmentManager = ComponentAccessor.getAttachmentManager()
def userSearchService = ComponentAccessor.getComponent(UserSearchService)
def issueManager = ComponentAccessor.getIssueManager()
def constantsManager = ComponentAccessor.getConstantsManager()
def adminUser = ComponentAccessor.getUserManager().getUserByName("anon@anon.local")
if(!adminUser) {
    adminUser = ComponentAccessor.getUserManager().getUserByName("admin")
}
def thisIssue = issueManager.getIssueObject('HHHT-5331')
def issue = thisIssue as MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfList = customFieldManager.getCustomFieldObjectsByName("Employee's Email Address")//getField
def rawValue = issue.getCustomFieldValue(cfList.first())
log.warn("Raw Value= " + rawValue + ".")
log.warn("User: " + issue.getClass())
def ncrField = customFieldManager.getCustomFieldObjectsByName("Employee Email Address")//setField
ModifiedValue modifiedValue = new ModifiedValue(issue.getCustomFieldValue(ncrField.first()), rawValue)
cfList.updateValue(null, issue, modifiedValue, new DefaultIssueChangeHolder())

//endregion
return "Done!"
Error:
groovy.lang.MissingMethodException: No signature of method: com.google.common.collect.SingletonImmutableList.updateValue() is applicable for argument types: (null, com.atlassian.jira.issue.IssueImpl, com.atlassian.jira.issue.ModifiedValue...) values: [null, HHHT-5331, com.atlassian.jira.issue.ModifiedValue@52f3f80e, ...] at Script119.run(Script119.groovy:39) ~[?:?]

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
This widget could not be displayed.
TAGS
AUG Leaders

Atlassian Community Events