ScriptRunner Groovy Script if checkbox contains update custom field

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

This looks very wrong:

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

you probably meant:

if (sourceValue*.value.contains("Support"))

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.

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
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

357 views 0 1
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you