Setting field value from a script, if executed by a user without permission to view or modify the secure field

1 2 3 4 5 6 7 8 9 10 11 def authContext = ComponentAccessor.getJiraAuthenticationContext(); def privilegedUserForCF = ComponentAccessor.getUserManager().getUserByName('privileged user name') def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() try { authContext.setLoggedInUser(privilegedUserForCF); //Sets authentication context from this moment to user who can perform Secure field operations //perform CF operations here } finally { authContext.setLoggedInUser(currentUser); //Restores original auth context. Must be in finally clause to be executed even in case of exception }