I have created a Single Select Single Choice custom field and named it "CF Name". It can have several values one of which is "CF Value". I have the following code in a Post Function to validate "CF Name" and assign the ticket to a particular team member called user@company.com,
Here is my code. When I remove the If statement my post function works and ticket gets assigned to user@company.com. But when I put the validation in it does not make an assignment. Can anyone help please.
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager(); CustomField customField_name = customFieldManager.getCustomFieldObjectByName('CF Name'); issue.summary = ('For your Review: ' + issue.summary); if(customField_name == "CF Value") { issue.assigneeId = 'user@company.com'; }
Community moderators have prevented the ability to post new answers.
I don't think cfValues is available in normal scripts, it's just conditions, although I could be totally wrong. But you don't want the spread-dot operator (asterisk), that's for multi selects. This should work:
if(issue.getCustomFieldValue(customField_name)?.value == "CF Value") {...}
Learned someting new ;-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Jamie Echlin [Adaptavist]
Is there any way I can use your function with "contains" to validate against a string like what @Udo Brand has done in his code. As an example I have used this before to validate a component against a value. Thanks!
if issue.components.name*.contains('VALUE') { ... }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you want to check for a single select having any of a list of values, or a multiselect containing a particular value, or a multiselect containing any of a list of values?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jamie Echlin [Adaptavist] Thanks for your quick response! It is for a single select/single choice Custom Field that can contain any of a list of values. List of values may be prefixed by a common string. For example the custom field may have these values: Customer_aaa Customer_bbb Customer_ccc I'd like to validate the custom field value against "Customer_". Hope that makes sense, Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try
if(cfValues['CF Name']*.value.contains("CF Value")) {...}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your response. I had tried your function already and it was not successful. As @Jamie Echlin [Adaptavist] says it does not appear that cfValue is available in generic scripts. It is available in built-in scripts though.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.