ScriptRunner Groovy Script if checkbox contains update custom field

David Thompson February 5, 2015

Hi,

I'm learning groovy scripting (early days) and testing script runner post functions.

I have one custom multi checkbox field that has email addresses as the options.

I'm trying the approach if the checkbox contains certain text to then to create a variable which will be the email address and then add this to a single line text custom field.

Reason being I'm using the JEMH plugin and you can use custom fields as the "To:" addresses but it doesn't support multi checkboxes but normal text fields are fine.

So far I'm just testing with one if statement and trying to update the custom text field with one variable.

I believe I haven't quite grasped checking the value in the source custom multi checkbox field. So would be thankful for a steer in the right direction. The post function with the script below doesn't cause an error in the logs but doesn't update the text field.

Thanks,

David

 

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;

ComponentManager componentManager = ComponentManager.getInstance();
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();

CustomField source = customFieldManager.getCustomFieldObject("customfield_10468");
CustomField target = customFieldManager.getCustomFieldObject("customfield_11521");

sourceValue = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10468"))

if (['sourceValue']*.value.contains("Support")) {

supportValue = "support@domain.com,";

issue.setCustomFieldValue(target, supportValue)
}

 

 

2 answers

1 accepted

1 vote
Answer accepted
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 5, 2015

This looks very wrong:

if (['sourceValue']*.value.contains("Support"))

you probably meant:

if (sourceValue*.value.contains("Support"))
David Thompson February 6, 2015

Hi Jamie, Thank you for your assistance, though it maybe a small thing it has helped me progress. After some thinking and more learning I have ended up with the following which seems more suited to solving what I needed for looking for all the options selected in the checkbox. With the script below I can now get all the options from the checkbox and put these into a string, formatted in a way I can use for the JEMH email addresses. Thanks again, a lot of my learning comes from your comments in this Atlassian answers site.

1 vote
David Thompson February 6, 2015
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;

ComponentManager componentManager = ComponentManager.getInstance();
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();

CustomField source = customFieldManager.getCustomFieldObject("customfield_10468");
CustomField target = customFieldManager.getCustomFieldObject("customfield_11521");

sourceValue = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10468"))

if(sourceValue !=null){ 
contentsSourceValue = sourceValue.join(", ")

issue.setCustomFieldValue(target, contentsSourceValue)
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events