Missed Team ’24? Catch up on announcements here.

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

How to set "none" cascade select list to child

Juan José Marchal Gómez
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.
January 14, 2020

Hello,

 

when I use the following code to reset child option in cascade select list is not working.

Could you help me?

Best regards.

 

_________________________

I checked with:

def fieldConfig = customField.getRelevantConfig(issue)

def options = optionsManager.getOptions(fieldConfig)
def parentOption = options.find {it.value == parentValue}
def childOption = "none"

cfModule.setFormValue(parentOption.optionId, childOption )

 

And

def fieldConfig = customField.getRelevantConfig(issue)

def options = optionsManager.getOptions(fieldConfig)
def parentOption = options.find {it.value == parentValue}
def childOption = null

cfModule.setFormValue(parentOption.optionId,childOption )

 

 

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Yury Lubanets January 20, 2020

Hi @Juan José Marchal Gómez 

You can try the code below I usually use for that purpose

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('cfName').first()
def fieldConfig = cf.getRelevantConfig(issue)
def option = ComponentAccessor.optionsManager.getOptions(fieldConfig).find {it.value == parentValue}
def iip = ComponentAccessor.issueService.newIssueInputParameters().with {
addCustomFieldValue(cf.id, option.optionId.toString() )
addCustomFieldValue(cf.id + ':1', null )
}
def uvr = ComponentAccessor.issueService.validateUpdate(user, issue.id, iip)
ComponentAccessor.issueService.update(user, uvr)
Juan José Marchal Gómez
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.
January 22, 2020

Hello @Yury Lubanets ,

your code works perfectly.

I spent some time to adapt to my system and check it in "prelive" but this code works perfectly. 

Thanks a lot for your help.

 

My final code is something like:

 

//set version none
log.info("---------- SET VERSION NONE ----------")
def fieldConfig = cfModule.getRelevantConfig(issue)
def option = ComponentAccessor.optionsManager.getOptions(fieldConfig).find {it.value == parentValue.toString()}
log.warn("Parent: " + parentValue)
log.warn("fieldConfig: " + fieldConfig)
def iip = ComponentAccessor.issueService.newIssueInputParameters().with
{
addCustomFieldValue(cfModule.id, option.optionId.toString())
addCustomFieldValue(cfModule.id + ':1', null )
}
def uvr = ComponentAccessor.issueService.validateUpdate(user, issue.id, iip)
log.info("issueServiceUpdate")
ComponentAccessor.issueService.update(user, uvr)
Like Yury Lubanets likes this
1 vote
Nic Brough -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.
January 14, 2020

"none" is what Jira displays when a select-type field is empty.  It's not actually "none", it's <nothing here>

I have not tried it for myself (as I'm not sure where you might be coding), but try

def childOption = ""

or

def childOption = null

Juan José Marchal Gómez
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.
January 14, 2020

Hello @Nic Brough -Adaptavist- ,

in your documentation there are examples "how to set" but I think any about "how to release" :)

I checked also def childOption = "" with no success.

Always appears the same error:

 

IF ""

No signature of method: com.atlassian.jira.issue.fields.ImmutableCustomField.setFormValue() is applicable for argument types: (java.lang.Long, java.lang.String) values: [10233, ] at Script1947.run(Script1947.groovy:48)

 

IF null

No signature of method: com.atlassian.jira.issue.fields.ImmutableCustomField.setFormValue() is applicable for argument types: (java.lang.Long, null) values: [10233, null] at Script1950.run(Script1950.groovy:48)

 

Actually, If I do 

log.warn(parentOption?.childOptions?.toString())

 

the information is:

[20191201, 20191101, 20191001, 20190801, 20190701, 20190601, 20190501 , 20190401, 20190301, 20190101, 20181201, 20181101]

so in my opinion is dificult "to set null or empty because in the map of child there is no this option.

 

Thanks for you quick first answer.

 

Best regards.

TAGS
AUG Leaders

Atlassian Community Events