I need to make required a customfield using Behaviour plugin depending on project.
What do I need to include in my script for doing this?:
if(getActionName() == "Create"){ getFieldByName("customfieldXXXX").setRequired(true) }
Hi Begona,
You can achieve your requirement using the behaviours module of the ScriptRunner plugin by following the instructions below. This does not require any groovy code to be written and can be achieved by using the built in functionality provided by Behaviours.
Steps:
I hope this helps
Kristian
You can create a script validator. Something like the following maybe is what you need
import org.apache.log4j.Category; import com.atlassian.jira.ComponentManager; import com.opensymphony.workflow.InvalidInputException; import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.MutableIssue; import com.atlassian.jira.issue.comments.CommentManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.util.ImportUtils; import com.opensymphony.util.TextUtils import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.project.Project; // creates the project object Project project = issue.getProjectObject(); //Get Project id Long pr_id = project.getId(); if ( pr_id == xxxxx ){ CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); //Get Custom Field Value CustomField customField_xxxxx = customFieldManager.getCustomFieldObject( xxxxx ); if (!issue.getCustomFieldValue( customField_xxxxx )) { invalidInputException = new InvalidInputException("customfield_{id}", "Custom field is required.") } }
My behaviour is mapped to 4 different projects and only in one of them the customfieldXXX is required in Create action. For the other projects this field must be optional.....I think I need to use an script...
You should creaate a seperate behaviour for the one project that the field is required.
This will be a more stable approach and will not break if any apis change in future.
I'll try Kristian but I think that I had problems when I used 2 different Behaviours for the same workflow..... perhaps I'm wrong....
I've solved the problem but I'll test also your solution! Thanks!
Np! if you need feedback feel free to ask.
Thanks Kostas!
It looks like you're new here. Sign in or register to get started.