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

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

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

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

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

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 } }

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

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

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

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.

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.

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
Community showcase
Posted in Off-topic

Friday Fun: Virtual dance party!

Do dance parties help you relieve stress? How about *virtual dance parties*? My team holds virtual dance parties to brighten the mood of a tough day or celebrate an upcoming weekend.  Want t...

194 views 22 9
Join discussion

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