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

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

PRAMOD KUMAR REDDY KASIREDDY September 19, 2022

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

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 20, 2022

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

PRAMOD KUMAR REDDY KASIREDDY September 20, 2022

Hi, @Ram Kumar Aravindakshan _Adaptavist_,

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

 

Thanks and Regards

Pramod,

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 20, 2022

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

PRAMOD KUMAR REDDY KASIREDDY September 20, 2022

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

SubDelivey is a Muti-Select field, Not Cascade.

Thanks and Regards

Pramod

PRAMOD KUMAR REDDY KASIREDDY September 20, 2022

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

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

 

Thanks and Regards

Pramod

PRAMOD KUMAR REDDY KASIREDDY September 20, 2022

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.

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 21, 2022

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 

PRAMOD KUMAR REDDY KASIREDDY September 22, 2022

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
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 19, 2022

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.

PRAMOD KUMAR REDDY KASIREDDY September 20, 2022

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.

PRAMOD KUMAR REDDY KASIREDDY September 20, 2022

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()

PRAMOD KUMAR REDDY KASIREDDY September 20, 2022

The above script is Not working.

TAGS
AUG Leaders

Atlassian Community Events