Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Scripted Data Resource UI Builder

leonarddimi
Tera Contributor

Hi 

I'm trying to use some scripted data resource in UI Builder for a report (data visualization - type: vertical Bar). I've tried many and I have the following findings: 
- if I use "Add data manually" and paste a JSON with the data that I want to display it's working fine and data is visible in the report

- if I add the desired output in the script source it's not working and I receive an error  "Cannot convert undefined or null to onject"

This is the script that I'm trying to use (hardcoded output)

function evaluateProperty({
api,
helpers
}) {
const output = [{
"data": [{
"priority": "1 - Critical",
"value": "28"
}, {
"priority": "2 - High",
"value": "12"
}, {
"priority": "3 - Moderate",
"value": "9"
}, {
"priority": "4 - Low",
"value": "9"
}, {
"priority": "5 - Planning",
"value": "6"
}],
"metadata": {
"dataSourceLabel": "Incident",
"eventData": {
"table": "incident"
},
"groupBy": [{
"id": "priority",
"fieldType": "integer",
"label": "Priority",
"series": [{
"id": "value",
"type": "value",
"label": "Incident"
}],
"elements": [{
"eventData": {
"query": "priority=1"
},
"id": "1",
"label": "1 - Critical"
}, {
"eventData": {
"query": "priority=2"
},
"id": "2",
"label": "2 - High"
}, {
"eventData": {
"query": "priority=3"
},
"id": "3",
"label": "3 - Moderate"
}, {
"eventData": {
"query": "priority=4"
},
"id": "4",
"label": "4 - Low"
}, {
"eventData": {
"query": "priority=5"
},
"id": "5",
"label": "5 - Planning"
}]
}],
"format": {
"unitFormat": "{0}"
},
"aggregateBy": 4
}
}];

return output;
}


Any ideea what could be the issue?
#ui builder 
#scripting
 

 

 

 

1 ACCEPTED SOLUTION

You are binding to the incorrect property, you want to tick the "define data manually" and then use the data property that will be shown below it.

Data sources would be an array of tables or indicators

Now Component Library | ServiceNow Developers

 

 

View solution in original post

3 REPLIES 3

lauri457
Tera Sage

Your script seems to work fine for me. Where are you trying to use it? And where is the error showing up, is it in the console? If it's in the console it should give you the sysid of the sys_ux_client_script record. Is it the one you expect?

function evaluateProperty({
    api,
    helpers
}) {
    const output = [{
        "data": [{
            "priority": "1 - Critical",
            "value": "28"
        }, {
            "priority": "2 - High",
            "value": "12"
        }, {
            "priority": "3 - Moderate",
            "value": "9"
        }, {
            "priority": "4 - Low",
            "value": "9"
        }, {
            "priority": "5 - Planning",
            "value": "6"
        }],
        "metadata": {
            "dataSourceLabel": "Incident",
            "eventData": {
                "table": "incident"
            },
            "groupBy": [{
                "id": "priority",
                "fieldType": "integer",
                "label": "Priority",
                "series": [{
                    "id": "value",
                    "type": "value",
                    "label": "Incident"
                }],
                "elements": [{
                    "eventData": {
                        "query": "priority=1"
                    },
                    "id": "1",
                    "label": "1 - Critical"
                }, {
                    "eventData": {
                        "query": "priority=2"
                    },
                    "id": "2",
                    "label": "2 - High"
                }, {
                    "eventData": {
                        "query": "priority=3"
                    },
                    "id": "3",
                    "label": "3 - Moderate"
                }, {
                    "eventData": {
                        "query": "priority=4"
                    },
                    "id": "4",
                    "label": "4 - Low"
                }, {
                    "eventData": {
                        "query": "priority=5"
                    },
                    "id": "5",
                    "label": "5 - Planning"
                }]
            }],
            "format": {
                "unitFormat": "{0}"
            },
            "aggregateBy": 4
        }
    }];

    return output;
}
 

 

 

leonarddimi
Tera Contributor

Screenshot 2026-02-23 at 00.42.19.pngScreenshot 2026-02-23 at 00.42.57.pngHello

I'm trying to use the script as a data source for data visualization in UI Builder
And yes, error is in the console. Maybe the format that I'm using as the output is not correct, but I wasn't able to find another structure

 

You are binding to the incorrect property, you want to tick the "define data manually" and then use the data property that will be shown below it.

Data sources would be an array of tables or indicators

Now Component Library | ServiceNow Developers