Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,551,840
Community Members
 
Community Events
184
Community Groups

behavior script add an option value depending on the user group

Hi,

 

i'm trying to create a groovy script with behavior to add an option value to a custum field depending on the reporter group.

The vlue mustbe setwhile creating the issue.

 

we have a custom field with 20 optiosn values and a match user groups with the same values.

The script can search for the user group and then try to make a match with the custom feld values and if find something it will set the values found on the customfield while creating the issue.

I have an old script and it stop working ( i think after we done the jira upgrade from 6.4 to 7.13 and the plugin has been updated also).

Here is the script we have now:

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.Permissions;
import org.apache.log4j.Category;

Category log = Category.getInstance("com.oddo.behaviours");
def cfSDGList = getFieldById("customfield_10061");
def cfOwner = getFieldById("customfield_10103");
def user = ComponentAccessor.JiraAuthenticationContext.getLoggedInUser();
cfSDGList.setRequired(true);

Boolean fieldVisible = !ComponentAccessor.getGlobalPermissionManager().hasPermission(Permissions.USER_PICKER, ComponentAccessor.jiraAuthenticationContext.user)
//cfSDGList.setHidden(fieldVisible);
//cfSDGList.setReadOnly(fieldVisible);
//cfSDGList.setRequired(fieldVisible);
Map fieldOptions = [:] ;
fieldOptions.put ("13940", "Undefined") ;
def optionToSelect;

//find the team the user belongs to
def groupList = ComponentAccessor.getGroupManager().getGroupsForUser(user);
def reporterTeamGroup = groupList.find { !( it.value !== /(jira\-.*|Dash.*|Clients)/ ) }
//If we founbd a matching group, find the possible options of the SdG List Field
if (reporterTeamGroup) {
def optionsManager = ComponentAccessor.getOptionsManager();
def cfSDGListCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(cfSDGList.getFieldId());
def fieldConfig = cfSDGListCF.getRelevantConfig(getIssueContext());
def options = optionsManager.getOptions(fieldConfig);
//set the CF values
optionToSelect = options.find { it.value == reporterTeamGroup.split(" - ")[0] };
}
//If we found something, add the value to the list of filtered options, and set the option of the select list we found if it isn't already defined (empty or "Undefined")
if (optionToSelect) {
fieldOptions.put (optionToSelect.getOptionId().toString(), optionToSelect.getValue()) ;
if ((!getUnderlyingIssue()?.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10061"))) || (cfSDGList.getValue()=="Undefined") ) {
cfSDGList.setFormValue(optionToSelect.getOptionId());
}

}

if (fieldVisible) {cfSDGList.setFieldOptions (fieldOptions);}
if (!getUnderlyingIssue()?.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10103"))) {cfOwner.setFormValue(user);}
cfSDGList.setRequired(true);

 

 

Thanks in advance and sorry i'm trying to learn groovy.

 

Best Regards,

Wajih

1 answer

Hello

What is the error? Could you add error details here?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events