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 widget could not be displayed.

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.

This widget could not be displayed.
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 Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

492 views 3 18
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