SR groovy script is throwing ERROR while changing the custom field value to match with Reporter valu

Hi,

I am facing below ERROR with my below post function script. Please let me know what is the wrong in the script used while re-assigning the reporter value/user to Test Manager custom field value? 

2017-06-06 17:20:01,541 ERROR [utils.WorkflowUtils]: In-depth checking of each condition follows to determine why the action was not allowed.
2017-06-06 17:20:01,542 ERROR [utils.WorkflowUtils]:
 (PASS)
 PASS: Only users in project role Release(INT) can execute this transition.
2017-06-06 17:20:01,543 ERROR [utils.WorkflowUtils]: {customfield_10034=Could not find usernames: admin(admin)}
2017-06-06 17:20:01,543 ERROR [utils.WorkflowUtils]: Not attempting transition because of above errors.

My post function script as follows::

import com.atlassian.jira.component.ComponentAccessor
String reporter = issue.reporter
issue.setAssigneeId(reporter)
def componentCF0 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test Managers")
def selectedComponents0 = issue.getCustomFieldValue(componentCF0)

issue.setCustomFieldValue(componentCF0, reporter)

issueInputParameters.setComment('Re-Assiging to Design PR Reporter to validate and close the PR has it has not ITG Test Scope ')

//def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Test Managers'}
//issueInputParameters.addCustomFieldValue(cf.id, reporter)
//issue.setCustomFieldValue(selectedComponents0, reporter)

My issue has the below details and trying to change the Test Manager custom field value to Reporter name using the above script in my transition post function.

  • Assignee: admin(admin)admin(admin) Reporter: adminadmin Release Prime:
    Server-release
    Module Owner: Platform-Support Primary Owners:
    Manjunatha K R
    Test Managers:
    Manjunatha K R

The following will be processed after the transition occurs

  1.  
    The field Secondary Owners will take the value from Test Que Secondary Owners. Source and destination issue are the same.
  2.  
    The field Primary Owners will take the value from Test Managers. Source and destination issue are the same.
  3. Set issue status to the linked status of the destination workflow step.
  4. Add a comment to an issue if one is entered during a transition.
  5. Update change history for an issue and store the issue in the database.
  6. Re-index an issue to keep indexes in sync with the database.
  7.  
    Fire a Generic Event event that can be processed by the listeners
    ScriptRunner workflow function - Fast-track transition an issue (condition & additional actions apply).
    Action: Release Update (1051) will be applied
    Note that this should go after the Fire Event function.
     - Manju

1 answer

I tried to modify my groovy script as below based on one community answer shared it before, now there is no ERROR seen. But modified value for Test Managers custom field is not displayed in the Jira issue screen and has old value only. Eventhough i am able to get the modified value correctly in the script using log.info()

Do I still missing something in my below script??? Please advice.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

String reporter = issue.reporter?.name
issue.setAssigneeId(reporter)
def componentCF0 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test Managers")
def selectedComponents0 = issue.getCustomFieldValue(componentCF0)

issue.setCustomFieldValue(componentCF0, reporter)
Object cfVal = issue.getCustomFieldValue(componentCF0)
log.info(cfVal)
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder()
componentCF0.updateValue(null, issue, new ModifiedValue("", reporter), changeHolder);

issue.store();

issueInputParameters.setComment('Re-Assiging to Design PR Reporter to validate and close the PR has it has not ITG Test Scope ')

 

Hi,

Please find the working post function script as per the specific use case shared in this question/community/FYR.

But somehow same postfunction working script doen's work in when we use in Fast-track transition - not sure why?

ScriptRunner workflow function - Fast-track transition an issue (condition & additional actions apply

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser

def componentCF2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("ITG To Test")
String selectedComponents2 = issue.getCustomFieldValue(componentCF2)

def componentCF1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Defect Source")
String selectedComponents1 = issue.getCustomFieldValue(componentCF1)

if(selectedComponents1 == "Design Server" && selectedComponents2 == "NO")
{
String reporter = issue.reporter?.name
issue.setAssigneeId(reporter)

String reporter1 = issue.reporter?.name
CustomField multiUser = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test Managers")
List<ApplicationUser> users;
//= (List<ApplicationUser>) issue.getCustomFieldValue(multiUser)
if(users == null)
    users = new ArrayList<>();

users.add(ComponentAccessor.getUserManager().getUserByName(reporter1))

issue.setCustomFieldValue(multiUser, users);
}    

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published 9 hours ago in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

34 views 0 3
Read article

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