Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Setting CustomField value from another CustomField

Hello to everyone!

I wrote a script that must to change assignee in an issue, but it doesn't work without any error. 

I have "customfield_10300" (Epic Link) and username "jandall". This script runs in postfunctions via ScriptRunner. But when I changing the transition of issue or creates it nothing happens. Script runs but with no changing of assignee.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

MutableIssue curIssue = issue

def condField = "customfield_10300"

def target = "assignee"

def cfManager = ComponentAccessor.getCustomFieldManager()
def cfCond = cfManager.getCustomFieldObject(condField)
def selectedVal = cfCond.getValueFromIssue(curIssue)

def cfTarget = cfManager.getCustomFieldObject(target)

if (selectedVal == "TBAS-1") {
curIssue.setCustomFieldValue(cfTarget, "jandall")
} else if (selectedVal == "TBAS-2") {
curIssue.setCustomFieldValue(cfTarget, "mdavis-sd-demo")
}

 

What am I doing wrong?

1 answer

1 accepted

1 vote
Answer accepted

Assignee is not a custom field, unless you've added a new one called that.  Can you confirm if you mean the standard system assignee, or you have a new custom field called assignee?

Yes, I mean standard system assignee.

Right, so you can probably see why your code does not work - assignee is not a custom field, so you don't use set custom field functions.

Try .setAssignee(<user>) instead.  You'll need a the user to be a user object, not a string

Thanks, it works well!

My final script for issue:

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.component.ComponentAccessor;

MutableIssue curIssue = issue;

def issueManager = ComponentAccessor.getIssueManager();
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cField = customFieldManager.getCustomFieldObject("customfield_10000");
def cFieldValue = issue.getCustomFieldValue(cField);

String epicLink = cFieldValue;
String chs-admindev = "CHS-6";
String chs-design = "CHS-10";
String content = "CHS-28";
String mobilemarketing = "CHS-29";

String user = 'defaultuser';

if (epicLink == chs-admindev) {
user = 'user1';
}

if (epicLink == chs-design) {
user = 'user2';
}

if (epicLink == content) {
user = 'user3';
}

if (epicLink == mobilemarketing) {
user = 'user4';
}

issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(user));

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

109 views 0 7
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you