I have a script that makes a field mandatory in the create transition, but now I need to add another condition into the code so that the field is only mandatory if the username of the creator does NOT contain 'Portal'.
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def CustomFieldValue1 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Retailer ID"));
def CustomFieldValue2 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Retailer ID List"));
if(CustomFieldValue2 == " Please select..."){
invalidInputException = new InvalidInputException("Please Select From Retailer ID List")
}
Can anyone help?
Incidentally, by 'Portal' you mean reporter name or customer request channel type?
Sorry, yes Portal is just a username
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok. Try this:
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def CustomFieldValue1 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Retailer ID"));
def CustomFieldValue2 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Retailer ID List"));
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
if(CustomFieldValue2 == null && currentUser.getUsername() == "Portal"){
throw new InvalidInputException("Please Select From Retailer ID List")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if(CustomFieldValue2 == null && currentUser.getUsername() != "Portal"){
throw new InvalidInputException("Please Select From Retailer ID List")
}
"Portal" user can still create the issue without selecting Retailer ID List.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ignore me it worked fine! Thanks for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can use
ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do i just put that in anywhere? Sorry a bit of a beginner to this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.