Forums

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

Error on select data for custom picker field

Harald Hiebl October 25, 2025

Hi,

I have configured a csutom picker field for data from ServiceNow, but on loading options I get following error:

Error searching: java.lang.UnsupportedOperationException 

java.lang.UnsupportedOperationException
at org.codehaus.groovy.runtime.ConvertedMap.invokeCustom(ConvertedMap.java:52) at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:113) at jdk.proxy1/jdk.proxy1.$Proxy5118.isEmpty(Unknown Source)

My code for the field is:

 

HTTPBuilder getHttpBuilder() {
    new HTTPBuilder("https://xxx.com"
    )
}

search = {
    HttpBuilder.request(Method.GET, ContentType.JSON) {
        headers.Accecpt = 'application/json'
        headers."x-sn-apikey" =  "<TOKEN>"
        uri.path = "/api/now/v2/table/cmdb_ci_service_business"
        uri.query = [fields: 'sys_id, name']
    }
}

toOption = { Map<String, String> map, Closure<String> highlight ->  
    new PickerOption(        
        value: map.sys_id,
        label: map.name,    

        html: highlight(map.sys_id, false)
    )
}
Any idea, why the json object can not be converted to a map?

If I create a separate output for the http request, all data are available:

def output = HttpBuilder.request(Method.GET, ContentType.JSON) {
    headers.Accecpt = 'application/json'
    headers."x-sn-apikey" =  "<TOKEN>"

    uri.path = "/api/now/v2/table/cmdb_ci_service_business"
    uri.query = [fields: 'sys_id, name']      

    response.failure = { null }
}
def bsNumber = output["result"]*."number"
def bsName = output["result"]*."name"
def bsSys = output["result"]*."sys_id"

log.info(bsNumber)
log.info(bsName)
log.info(bsSys)
example for one dataset:
[
{
"attested_date": "",
"parent": "",
"operational_status": "7",
"consumer_type": "internal",
"sys_updated_on": "2025-04-28 15:43:02",
"total_vulnerable_items": "",
"u_urgency": "2",
"number": "BSN0002089",
"published_ref": "",
"discovery_source": "",
"first_discovered": "",
"due_in": "",
"used_for": "Production",
"state": "",
"gl_account": "",
"invoice_number": "",
"sys_created_by": "xxxxx",
"warranty_expiration": "",
"vulnerability_risk_score": "",
"owned_by": {
"link": "<LINK>",
"value": "7110acd2eb8a1610e5d8f03dcad0cdee"
},
"checked_out": "",
"sys_domain_path": "/",
"business_unit": "",
"version": "",
"u_description": "<DESCRIPTION>”,maintenance_schedule": "",
"cost_center": "",
"attested_by": "",
"dns_domain": "",
"service_status": "requirements",
"assigned": "",
"life_cycle_stage": "",
"portfolio_status": "pipeline",
"purchase_date": "",
"u_upstream_support_group": "",
"business_need": "",
"delivery_manager": "",
"end_date": "",
"short_description": "<DESCRIPTION>,",
"busines_criticality": "2",
"u_business_contacts": "7110acd2eb8a1610e5d8f03dcad0cdee",
"managed_by": {
"link": "<LINK>",
"value": "763498da4782d210c2fce2d5536d43fc"
},
"stakeholders": "",
"can_print": "false",
"last_discovered": "",
"service_owner_delegate": "",
"sys_class_name": "cmdb_ci_service_business",
"manufacturer": "",
"life_cycle_stage_status": "",
"vendor": "",
"model_number": "",
"u_secondary_routing_group": {
"link": "<LINK>",
"value": "1aff5f883b3a82108368952a85e45a81"
},
"assigned_to": "",
"start_date": "2018-03-29 22:00:00",
"u_billable": "1",
"serial_number": "",
"price_unit": "",
"support_group": {
"link": "<LINK>",
"value": "a96f9fb33bcf8a508733a50c95e45a82"
},
"correlation_id": "",
"unverified": "false",
"attributes": "",
"asset": "",
"u_base_topic": {
"link": "<LINK>"value": "df4b100c3b2d1a108733a50c95e45a28"
},
"skip_sync": "false",
"aliases": "",
"product_instance_id": "",
"u_request_assignment_group": {
"link": "<LINK>",
"value": "a96f9fb33bcf8a508733a50c95e45a82"
},
"attestation_score": "",
"service_level_requirement": "",
"sys_updated_by": "",
"sys_created_on": "2024-11-26 11:23:19",
"sys_domain": {
"link": "<LINK>",
"value": "global"
},
"install_date": "",
"u_meta": "",
"monitoring_requirements": "",
"asset_tag": "",
"user_group": "",
"fqdn": "",
"change_control": {
"link": "<LINK>",
"value": "d566f4daeb6d96108033f1512bd0cdf5"
},
"unit_description": "",
"business_relation_manager": "",
"last_review_date": "",
"u_budget_code": "FCC",
"u_problem_coordinator_group": {
"link": "<LINK>",
"value": "df05bc5aeb6d96108033f1512bd0cdb9"
},
"business_contact": "",
"compatibility_dependencies": "",
"delivery_date": "",
"install_status": "1",
"supported_by": "",
"name": "<NAME>",
"subcategory": "",
"price_model": "per_unit",
"u_tertiary_routing_group": {
"link": "<LINK>",
"value": "549dfc56ebad96108033f1512bd0cdf0"
},
"assignment_group": {
"link": "<LINK>",
"value": "e647781eeb6d96108033f1512bd0cdcf"
},
"managed_by_group": "",
"u_monitoring_routing_group": {
"link": "<LINK>",
"value": "1aff5f883b3a82108368952a85e45a81"
},
"prerequisites": "",
"sys_id": "00a51dea47c25610c2fce2d5536d4345",
"po_number": "",
"checked_in": "",
"sys_class_path": "/!!/!7/!!",
"mac_address": "",
"company": "",
"justification": "",
"department": {
"link": "<LINK>",
"value": "3a3498da4782d210c2fce2d5536d43fc"
},
"checkout": "",
"comments": "",
"cost": "",
"attestation_status": "Not Yet Reviewed",
"sys_mod_count": "1",
"monitor": "false",
"ip_address": "",
"model_id": "",
"duplicate_of": "",
"sys_tags": "",
"u_technical_abbreviation": "fcc",
"cost_cc": "USD",
"order_date": "",
"schedule": "",
"environment": "",
"u_ownership_group": "",
"due": "",
"u_department_lead_service_owner": "",
"attested": "false",
"u_major_incident_commander": {
"link": "<LINK>",
"value": "40753eb13be516508733a50c95e45a60"
},
"u_teamlead_service_owner": {
"link": "<LINK>",
"value": "c8e450de4782d210c2fce2d5536d43e2"
},
"location": "",
"category": "",
"fault_count": "0",
"lease_id": "",
"service_classification": "Business Service"
}
]
 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
October 26, 2025

Hi @Harald Hiebl

From your code, it appears you are trying to invoke an external REST service.

The main problem appears to be that the date is not being parsed correctly into JSON format.

Please refer to the approach provided in this ScriptRunner Example code. It provides a straightforward approach to making GET, POST, PUT, and DELETE requests to external services.

Since you are only making a GET request, you will only need to follow the GET request section of the code.

Let me know how it goes.

Thank you and Kind regards,
Ram

Harald Hiebl October 27, 2025

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

thank you for your tip - fetching data with this script works fine!

final externalUrl = "<URL>"
def getResponse = get(externalUrl, "/api/now/v2/table/cmdb_ci_service_business", "")

if (getResponse) {
   def responseGetMap = getResponse as Map<String, String>

   responseGetMap.each { map ->
      log.info(map.value.getAt('name'))
   }
}


But is it possible to populate the fetched data ('name') to a custom picker field?

with definition:

  • search
  • toOption
  • getItemFromId
  • renderItemViewHtml
  • renderItemTextOnlyValue

or do I have to use another option?

Kind regards,
Harald

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
October 29, 2025

Hi @Harald Hiebl

If you intend to populate the data from the JSON and display it in a List, for example, I suggest using a Single Line Text Field and converting it to a Single or Multi Select list using the approach provided in the ScriptRunner Documentation.

For your case, you can use the Create and Test Endpoint approach displayed in the Documentation and specify the Service Now URL you need to use.

The main point is that when using the approach above, whenever there is a change in the REST Endpoint data, it will dynamically update the options in the List.

I hope this helps to answer your question. :-)

Thank you and Kind regards,
Ram

Harald Hiebl October 30, 2025

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

I have tried your suggestion, first with GitHub --> erverything works fine:

Screenshot 2025-10-30 121159.png

and then with ServiceNow:
connection is OK, response is OK, filtered data is OK (log.info(serviceName) in REST endpoint), but no options are populated to the field:

Screenshot 2025-10-30 121603.png

my endpoint:

 

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
serviceNowBusinessServiceQuery(httpMethod: "GET", groups: ["jira-administrators","APP_CP_POI_jira-administrators"]) { MultivaluedMap queryParams ->
    def query = queryParams.getFirst("query") as String
    def rt = [:]
    if (query) {
        def httpBuilder = new HTTPBuilder("<URL>")
        def services = httpBuilder.request(Method.GET, ContentType.JSON) {
            uri.path = "/api/now/v2/table/cmdb_ci_service_business"
            uri.query = [sysparm_query:"nameLIKE$query"]
            headers."x-sn-apikey" =  "<TOKEN>"
            response.failure = { resp, reader ->
                log.warn("Failed to query ServiceNow API: " + reader.text)
                return Response.serverError().build()
            }
        }
        rt = [
            result : services["result"].collect { Map service ->
                def serviceName = service."name"
                log.info(serviceName)
                [
                    value: serviceName,
                    html : serviceName.toString().replaceAll(/(?i)$query/) { "<b>${it}</b>" },
                    label: serviceName
                ]
            },
            footer: "Choose service... (${services["result"].size()} of ${services?.total_count} shown...)"
        ]
    }
    return Response.ok(new JsonBuilder(rt).toString()).build()
}
my behaviour:
getFieldByName("Select your Business Service").convertToMultiSelect([
ajaxOptions: [
   url : getBaseUrl() +                 "/rest/scriptrunner/latest/custom/serviceNowBusinessServiceQuery",
   query : true,
   minQueryLength: 3,
   keyInputPeriod: 500,
   formatResponse: "general",
   ]
])
log file for search with 'con':
<BaseUrl>/rest/scriptrunner/latest/custom/serviceNowBusinessServiceQuery?query=con
{
"result": [
{
"value": "Flotten Car Configurator",
"html": "Flotten Car Configurator",
"label": "Flotten Car Configurator"
},
{
"value": "Car Configurator",
"html": "Car Configurator",
"label": "Car Configurator"
},
{
"value": "Confluence Collaboration Platform",
"html": "Confluence Collaboration Platform",
"label": "Confluence Collaboration Platform"
},
{
"value": "Network Site-2-Site Connectivity HQ_Old",
"html": "Network Site-2-Site Connectivity HQ_Old",
"label": "Network Site-2-Site Connectivity HQ_Old"
},
{
"value": "Workshop Control Panel",
"html": "Workshop Control Panel",
"label": "Workshop Control Panel"
},
{
"value": "Network Site-2-Site Connectivity INT",
"html": "Network Site-2-Site Connectivity INT",
"label": "Network Site-2-Site Connectivity INT"
},
{
"value": "Dealer Car Configurator",
"html": "Dealer Car Configurator",
"label": "Dealer Car Configurator"
},
{
"value": "Finance Contract Info",
"html": "Finance Contract Info",
"label": "Finance Contract Info"
},
{
"value": "Servicebuchung Online Config App",
"html": "Servicebuchung Online Config App",
"label": "Servicebuchung Online Config App"
}
],
}
do you have any idea why no options are populated?
Kind regards
Harald
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events