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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Clearing custom field value based on the selection and updating the new values

I have the following fields in our assign screen :

  1. Incident category
  2. Incident item.
  3. Incident summary.
  4. Technician office code
  5. select name 

on one screen whenever our users select the category and item and summary from the dropdown they will have to select the technician office code and the name of the individual will be displayed in the select name field.

The issue we are facing is that whenever we try to click on the other options in incident category for eg incident category has two options crm and hrms then if user selects crm the technician list name of that category will appear and when the user selects hrms the technician list of that category should appear but however when we try to change the category from CRM to HRMS the values of select name are not changing it retains the old category value .

We have two values in technician office code "109897" and "Company" we have to toggle between theses two options eg. first click on 109897 and then click on "Company" to update the field select name with correct value .

Is there any function which can update the value of select name as soon as the category is changed.

We are using below code to set the name field

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.bc.user.search.UserSearchService

def id = getFieldById("id")
def currentIssue = ComponentAccessor.getIssueManager().getIssueObject(Long.parseLong(id.getValue() as String))
String Technician_Office_Code = currentIssue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_161")) as String
log.error"Technician office code"+Technician_Office_Code

if(getFieldById(getFieldChanged()) != null ){
String assigneeName = getFieldById(getFieldChanged()
def selectAssignee = getFieldById("customfield_12")
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject(selectAssignee.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
List<Option> optionsSelect = new ArrayList<Option>()
def userSearchService = ComponentAccessor.getComponent(UserSearchService)
def users = userSearchService.findUsersByFullName(assigneeName)

List<String> test = new ArrayList<String>()

for(def user : users){
// test.add(user.getUsername())

test.add(user.getName())
}
for(String optionStr : test){
boolean f = true
for(def option : options){
if(option.getValue().trim().equals(optionStr.trim())){
optionsSelect.add(option)
f = false
break
}
}
if(f){
optionsSelect.add(optionsManager.createOption(config, 0, 0, optionStr))
}
}
def selected = [:]
selected += optionsSelect.collectEntries{
[(it.optionId.toString()) : it.value]
}
//log.error"-------------xxxxxx79xxxxxxx----"+optionsSelect
selectAssignee.setFieldOptions(selected)

}else{
getFieldById("customfield_12").setHidden(true)
getFieldById("customfield_12").setRequired(false)
getFieldById("customfield_12").setFormValue(null)
getFieldById(getFieldChanged()).setFormValue(null)

}

 

 

1 answer

Hi @Komal Parate

After reviewing your code, my first question is why are you trying to invoke the issue using the:

def currentIssue = ComponentAccessor.getIssueManager().getIssueObject(Long.parseLong(id.getValue() as String))

instead of just using the underlyingIssue, which is an inbuilt variable in the Behaviour? 

If your goal is to invoke the issue variable in the Behaviour during the creation of an issue, this is not the correct approach.

However, you can invoke the underlyingIssue variable in the Behaviour once the issue is created. To ensure that the variable is accessible only after the issue has been created, you can use this condition.

if(underlyingIssue) {
...
}

Also, why are you invoking the custom field using:-

String Technician_Office_Code = currentIssue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_161")) as String

You could just use:-

def customField = getFieldByName("Sample")
def customFieldValue = customField.value.toString()

or, if you want to update a field value field in the Behaviour, based on another field, you could invoke the value like:-

def list2 = getFieldByName("List2")

def customFieldManager = ComponentAccessor.customFieldManager
def optionManager = ComponentAccessor.optionsManager


def list2CustomField = customFieldManager.getCustomFieldObject(list2.fieldId)
def list2Config = list2CustomField.getRelevantConfig(issueContext)
def list2Options = optionManager.getOptions(list2Config)

Regarding your question about resetting your value, could you please share a print screen of your behaviour configuration? This is to get a better understanding of your current behaviour configuration and provide a better solution.

I am looking forward to your feedback.

Thank you and Kind Regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you