Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update custom field option same component list

debasish sahoo February 14, 2023

Let's say I have a component with the description "xyz"

I want to get the component name whose description is set as "xyz" to be updated as options for another custom field

1 answer

0 votes
Carlos Faddul
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.
February 15, 2023

@debasish sahoo Isn't that a bit redundant?

Update a field with a component field value. In theory you will only generate a "global" field for components, however you will have a "dirty" base of the field, as approximate and/or equal values would be included (with variations in the strings)

But if you want to do that, you have two options.

- Create a text field, copy the name of the xyz component and paste it in this field (not editable in screens)

or

- Create an automation for each project, going through all the components and storing them in an automation variable and then inserting the values in the field via api (webhook) Update custom field options (context) 

I hope I helped you.

If this post was helpful, mark it as "Accept Answer" , so you can help others who may have the same difficulties.

If your question has not been resolved, please post again with more details.

debasish sahoo February 16, 2023

Hello @Carlos Faddul ,

I was not clear enough, 

 

Lets say I have a component "testcomp" which has description mentioned as "program"

 

another component is there which do not have any description or it has some different  description other than "program "

then the custom field should list only those component which has description as "program" in its select list.

Carlos Faddul
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.
February 22, 2023

@debasish sahoo in this case you will need to use a little of the automation

  1. Trigger field change or anything similar
  2. Action> Create Variable > "tempDescription"
  3. Action> Send webrequest > Get Component ID and set "tempDescription"
  4. Action > Create Variable > "tempDescriptionAux"
  5. Action> Send webrequest > Get Component ID and set "tempDescriptionAux"
  6. Condition > if/else > tempDescription != Empty AND tempDescriptionAux = Empty
    1. Action> Send Webrequest Update a Component > set value of tempDescriptionAux with "tempDescription"

With this you can make our rule :)

debasish sahoo February 22, 2023

I was able to solve this using the script listener mapped with any issue chnage event.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.fields.config.manager.FieldConfigManager
import org.apache.log4j.Logger
import org.apache.log4j.Level

 

def issue = event.issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
final customFieldName = "App/Library"
def fieldConfig = ComponentAccessor.getComponent(FieldConfigManager).getFieldConfig(18305)
def componentManager = ComponentAccessor.getProjectComponentManager()
def components = componentManager.findAllForProject(issue.getProjectObject().id)
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObjectsByName(customFieldName).first()
def config = customField.getRelevantConfig(issue)
def optionValues = []
def customrow = []
def ref = ""
log.debug("startin component check")
components.each { component ->
if (component.getDescription() == "app-lib") {
def componentvalue = component.getName().toString()
customrow = [component.getName()]
def issueChangeHolder = new DefaultIssueChangeHolder()
optionValues = optionsManager.getOptions(fieldConfig)




def optionStrings = optionValues.collect { it.toString() }
def containsTargetValue = optionStrings.any { it.contains(componentvalue) }



ModifiedValue(issue.getCustomFieldValue(customField), customFieldValue);
if (containsTargetValue) {
log.debug("checking for if 1" +" "+ optionStrings)
return
}
else {
log.debug("adding field" +" "+ customrow +" "+"to" +" "+ optionStrings)
optionsManager.createOption(config, null, null, componentvalue)
}
}
}

 

log.debug("checking for final " + optionValues)
Like Carlos Faddul likes this

Suggest an answer

Log in or Sign up to answer