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

Custom script runner script - not working at all

Mario Günter Feb 11, 2015

Hi,

I try to set users to a field related to another field. Please see my coding. But it seems not to work at all. 
It is a custom post-script function 

/**
 * Created by guenterm on 11.02.2015.
 */
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

MutableIssue curIssue = issue

// Field-Value is related for copied value (Type: InTENSO [Dynamic Forms] - Dynamic Select)
def condField = "customfield_11091"

// Target-Field (Userfield - multiple)
def target = "customfield_11100"

// Get condFields value
def cfManager = ComponentAccessor.getCustomFieldManager()
def cfCond = cfManager.getCustomFieldObject(condField)
def selectedVal = cfCond.getValueFromIssue(curIssue)

// Related on value set targets field value
def cfTarget = cfManager.getCustomFieldObject(target)

// Now copy the value into target
if (selectedVal == "Cat") {
    curIssue.setCustomFieldValue(cfTarget, "user-x")
} else if (selectedVal == "Dog") {
    curIssue.setCustomFieldValue(cfTarget, "user-y,user-z")
}

Have you any ideas why it is not working? No error in atlassian-jira.log

Best Regards, Mario

2 answers

1 accepted

5 votes
Answer accepted
Andrey Kuzmin Feb 11, 2015

Try something like this.

cfTarget.updateValue(null, curIssue , new ModifiedValue(curIssue .getCustomFieldValue(cfTarget), "user-x"), new DefaultIssueChangeHolder());

Also you can try using API that i mensioned here

Mario Günter Feb 11, 2015

Hi Andrey, it seems not to work, I'll try to follow the API snippet and report back soon - Thanks!

Mario Günter Feb 11, 2015

Hi, I tried the APIs Doc. And this Snippet is not working, too -.- {code} import com.atlassian.jira.ComponentManager import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.issue.IssueInputParameters /** * Created by guenterm on 11.02.2015. */ IssueService issueService = ComponentManager.getIssueService(); IssueInputParameters issueInputParameters = issueService.newIssueInputParameters(); //Prio setzen: issueInputParameters.setPriorityId() issueInputParameters.addCustomFieldValue(11100L, "user-x"); {/code} I'm running on Jira version 6.3.5

Andrey Kuzmin Feb 11, 2015

Hey Mario. You forgot to add code from example UpdateValidationResult updateValidationResult = issueService.validateUpdate(user, issueId, issueInputParameters); if (updateValidationResult.isValid()) { IssueResult updateResult = issueService.update(user, updateValidationResult); if (!updateResult.isValid()) { // Do something } }

T.CON GmbH & Co. KG Feb 11, 2015

With that I could get it done! Thanks Andrey!!!

Khadhar Mohaideen Jun 01, 2017

I have a question here:

When setting a value for a custom-field, why we should give "user-x" - something like that? should we give current user name? if so, will the script work for other users?

I am trying copy one custom field's value to another customer field which is of type "single drop-down list".

 

thanks,
Khadhar

JamieA Jun 01, 2017

 Can you ask a new question with a bit more detail? This is 2+ years old.

miller j Oct 11, 2017

Hi Jamie,

I have a similar issue:

I need to set the date in a custom field based on due date and Custom field value(Yearly, Monthly etc.)

You can find my Question here

Please advice.

Thanks.

miller j Oct 11, 2017

Hi Jamie,

I have a similar issue:

I need to set the date in a custom field based on due date and Custom field value(Yearly, Monthly etc.)

You can find my Question

https://community.atlassian.com/t5/Jira-questions/Updating-a-date-custom-field-on-workflow-transition-with-a/qaq-p/653550

Please advice.

Thanks.

2 votes
JamieA Feb 12, 2015

For future reference, rather than saying "it doesn't work at all", can you explain what you expect to happen and what is actually happening, even if that's "nothing".

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

4,450 views 21 23
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