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,361,794
Community Members
 
Community Events
168
Community Groups

While creation of ticket based on Components, Custom Field (Drop Down-Single Choice) should update.

Edited

We have a list of Components mapped with SubDelivey (Custom Field). While creating a ticket if User Select Both Fields then no changes are required, but when the user selects the only component and does not select SubDelivery. then the script should work based on Components, and SubDelivery Should update.

2 answers

1 accepted

0 votes
Answer accepted

Hi @PRAMOD KUMAR REDDY KASIREDDY 

In your description, you mentioned:-

We have a list of Components mapped with SubDelivey (Custom Field). While creating a ticket if User Select Both Fields then no changes are required, but when the user selects the only component and does not select SubDelivery. then the script should work based on Components, and SubDelivery Should update.

This seems more like you are trying to create a Behaviour configuration. Can you please confirm if this is the approach you are trying to take? I am asking this so that I can provide a sample code.

If the answer is yes, the code you currently use will not work.

I am looking forward to your feedback.

Thank you and Kind regards,

Ram

Hi, @Ram Kumar Aravindakshan _Adaptavist_,

Yeah, You're Right, YES We are trying Behaviour configuration, Please Help on this Ram. 

 

Thanks and Regards

Pramod,

Hi @PRAMOD KUMAR REDDY KASIREDDY

Could you also please clarify what field type you are using for the SubDelivey?

Is it a Cascade Select List?

Thank you and Kind regards,

Ram

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

SubDelivey is a Muti-Select field, Not Cascade.

Thanks and Regards

Pramod

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Sir, hope you're doing good. can you please provide a sample code?

 

Thanks and Regards

Pramod

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

In our Project Components is Mandatory and SubDelivery Not Mandatory. That is the project lead's requirement. if User Select Component and SubDelivery Value is None, then SubDelivery Value should Update Based on Component Mapping. or else if the User selects both Components and SubDelivery. then there is no change required.
The requirement is If the User missed updating the SubDelivery field during issue creation, without any Error/Warning, the ticket has to be created with a value to the SubDelivery field based on the Component selected.

Note: There will be only One component selected every time.

Kindly help.

Hi @PRAMOD KUMAR REDDY KASIREDDY

For your requirement, you can try something like:-

import com.atlassian.jira.bc.project.component.ProjectComponentImpl
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def components = getFieldById(fieldChanged)
components.setRequired(true)

def componentsValue = components.value as List<ProjectComponentImpl>
def componentNames = componentsValue['name'] as String

def sampleMulti = getFieldByName('Sample Multi Select')

def selectedOptions = []

if (componentNames == '[Component 1, Component 2, Component 3]') {
selectedOptions = ['Multi 1', 'Multi 2', 'Multi 3']
} else if (componentNames == '[Component 1, Component 3]') {
selectedOptions = ['Multi 1', 'Multi 3']
} else if (componentNames == '[Component 2, Component 3]') {
selectedOptions = ['Multi 2', 'Multi 3']
} else if (componentNames == '[Component 1, Component 2]') {
selectedOptions = ['Multi 1', 'Multi 2']
} else if (componentNames == '[Component 1]') {
selectedOptions = ['Multi 1']
} else if (componentNames == '[Component 2]') {
selectedOptions = ['Multi 2']
} else if (componentNames == '[Component 3]') {
selectedOptions = ['Multi 3']
}
sampleMulti.setFormValue(selectedOptions)

Please note that the sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications.

Also, it is not be possible to restrict the updating of the Multi-Select list even though a value has already been selected for it. 

Thank you and Kind regards,

Ram 

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

Hi Thanks for the script.. if we use in behaviours then by selecting the components value automatically SubDelivery filed value gets updated.. but the requirement is, if the User miss or intentionally not update the subdelivery filed it should filled as per the component selected.

So that validation should happen while click in Create button.. so Workflow post functions or listener helps I feel.. plz feel free to correct me..if My assumption is wrong.

Thanks and Regards

pramod 

0 votes

Are you trying to calculate the field, or just select a different value from the list (that the user can then change before committing to create the issue.

No Calculation is Required while Creating if they select Component and SubDelivery Then No Changes are Required. But if they only select Component they Automatically SubDelivery Value should be Update.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.fields.CustomField
final customFieldName = "SubDelivery"
def customField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
//IssueManager im = ComponentAccessor.getIssueManager();
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def userManager = ComponentAccessor.getUserManager()
def groupManager = ComponentAccessor.getGroupManager()
//def issueManager = ComponentAccessor.getIssueManager()
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Component/s")
MutableIssue curIssue = (MutableIssue) event.issue;
def cfConfig = cfSelect.getRelevantConfig(curIssue)
def value = []

def componentmap = ['component1':'AIVI_SW-PMs',
'component2':'Altran',
'component3':'CPM_AD2-ADASIS',]
def theComponent = ComponentAccessor.getProjectComponentManager().findByComponentName(curIssue.getId(),'Component/s')

for (e in componentmap)
{
if((curIssue.Component?.name, e.key))
{
value = value + ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {it.toString() == e.value}
}
}

curIssue.setCustomFieldValue(cfSelect, value)
ComponentAccessor.getIssueManager().updateIssue(user, curIssue, EventDispatchOption.ISSUE_UPDATED, false)
//curIssue.store()

The above script is Not working.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

211 views 1 6
Read article

Atlassian Community Events