Send API request Behaviour

fromero88 July 19, 2022

Hi,

 

I have a behaviour that converts another field into a MultiSelect list and retrieves the values of that list from an API REST, as we can see on the "Walkthrough - External REST Service" section of this official page: https://docs.adaptavist.com/sr4js/latest/features/behaviours/behaviours-examples/select-list-conversions

 

My multiselect list works fine when I'm on a form and I change another values. However, instead of show the label of every option in the list, I see the value key, which is stored in the field. How can I show the label instead of the value such as it works with the behaviour?

 

Next is the code of my behaviour and how I build the multiSelect list:

 

import com.atlassian.jira.component.ComponentAccessor
def
tipoCaso =  getFieldByName('Tipo de caso')
def servicio =  getFieldByName('Servicio SalesForce')
def modulo =  getFieldByName('Módulo SalesForce')
def campoServicio = ComponentAccessor.customFieldManager.getCustomFieldObjects(underlyingIssue).findByName('Servicio SalesForce')
def valorActualServicio = underlyingIssue.getCustomFieldValue(campoServicio).toString()

log.debug("Valor actual servicio")
log.debug(valorActualServicio)
log.debug("Valor cambio")
log.debug(getFieldById(getFieldChanged()).getValue().toString())

if (getFieldById(getFieldChanged()).equals(servicio) && (getFieldById(getFieldChanged()).getValue().toString() != valorActualServicio)) {
    modulo.setFormValue(null)
    def getOptionById = servicio.value.toString()//ComponentAccessor.getOptionsManager().getAllOptions().find{it.optionId == fieldChanged.value.toString()}

    log.debug("Cambia el servicio")

    modulo.convertToMultiSelect([
        ajaxOptions: [
            url           : getBaseUrl() + "/rest/scriptrunner/latest/custom/fnModulosPorServicio?servicioId="+getOptionById,
            query         : true, // keep going back to the sever for each keystroke
            minQueryLength: 4,
            keyInputPeriod: 500,
            formatResponse: "general",
        ]
    ])
}

 

And this is what I see on the jira view, or when I tried to edit the fields:
imagen.png

 

Thanks in advance!

1 answer

0 votes
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.
July 28, 2022

Hi @fromero88

I have read through your description, and I have a doubt, i.e. when do you want your Behaviour to take place?

Is it when you are creating a new issue or when you are editing an issue? If it is the former, your code may not work as expected because the underlyingIsuse will only be accessible after the issue has been created.

Secondly, why are you using the approach below to invoke the Sales Force field?

def campoServicio = ComponentAccessor.customFieldManager.getCustomFieldObjects(underlyingIssue).findByName('Servicio SalesForce')

Why not just invoke it as:-

def campoServicio = getFieldByName('Servicio SalesForce')

Also, if you could share a screenshot of your Behaviour configuration, it would be helpful to get a better understanding.

Looking forward to your feedback.

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer