I am trying to create a post-function in a "create issue" transition, and it is not working as expected. I am trying to use field values provided by users on the "create issue" screen to automatically set field values of the issue itself. However, my post function has no effect. I have read that the order of events in which the post function takes place matters, and I have tried moving the post function to all combinations of before and after the "Creates the issue originally" and "Re-index an issue to keep indexes in sync with the database." stages.
In some positions, I am able to access the user-provided field values but can't change them. In other positions, I am able to change the fields but I can't access the user-provided values. There does not appear to be a solution/location where I am able to *both* read the user-provided values *and* change them according to the script.
I have read the documentation about post-functions, for example this page:
https://docs.adaptavist.com/sr4js/latest/features/workflows/post-functions/custom-post-functions/custom-post-function-examples/set-issue-attributes
On this page, it mentions the importance of running your post-function "before the standard function" and if that doesn't work you need to "use a more complex method." But I am unable to find any information on this "more complex method"
Any assistance is appreciated (including pointing me in the direction of where I can learn more about this "more complex method")
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
import java.util.regex.*;
log.setLevel(Level.DEBUG)
def components = ComponentAccessor.projectComponentManager.findComponentsByIssue(issue)
log.info(components)
if(components != null){
def count = 0
//Get the list of component provided during the create screen
//Test look up their descriptions to see if they match some condition
def pattern = Pattern.compile("some-regex-here", Pattern.CASE_INSENSITIVE)
for(def component in components){
def compDesc = component.getDescription()
log.info(compDesc)
if(!compDesc) continue;
if(pattern.matcher(compDesc).find()){
count++
}
}
log.info("Match Count: " + count)
//Set a custom user field if the above component check matches
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10400")
if(count > 0){
log.info("Component match")
def user = ComponentAccessor.getUserManager().getUserByKey("myUser")
issue.setCustomFieldValue(cf, user)
}
}