Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Custom script runner script - not working at all

Mario Günter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

5 votes
Answer accepted
Andrey Kuzmin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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 February 11, 2015

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

Khadhar Mohaideen June 1, 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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 1, 2017

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

miller j October 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 October 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.

4 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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".

TAGS
AUG Leaders

Atlassian Community Events