Add carousel badge item count

task australia Updated Mar 12, 2026 3 min read add-carousel-badge-item-count.md
Raw file servicenow.com

How to create a dynamic carousel item count (displayed in the badge) where the items in the carousel are controlled by a repeater pulling its data from a data resource.

Before you begin

Role required: workspace_admin or ui_builder_admin

This procedure uses UI Builder components to create dynamic, interactive layouts. For more information on how to configure components, see:

Component

Documentation links

Carousel

\[Omitted video\] Description: Add Carousel badge item count

Procedure

  1. Set up Carousel to use a repeater pulling its data from a data resource.

  2. To create an object that determines the badge properties, open the page's Client state parameters dialog.

    [Omitted image "badge-edit-clientstateparams.png"] Alt text: Pointer hovering over selected Client state parameters and the Edit client state parameters dialog as it first appears

    1. Replace the Name with badgeConfigState, and from the Type dropdown, choose JSON.

      [Omitted image "badge-edit-02clientstateparams.png"] Alt text: Edit client state parameters dialog with the Name changed to badgeConfigState and JSON being selected from the Type dropdown

    2. Hover over the Initial value field box and select Edit.

    3. Choose the JSON type object from the dropdown.

    4. Select Add property and add the badge color, label, and variant properties.

      [Omitted image "badge-client-state01.png"] Alt text: Initial Value pop up with 3 properties added, color, label, and variant

    5. Select Apply to return to the Edit client state parameters dialog.

      [Omitted image "badge-client-state02.png"] Alt text: Returned to Edit client state parameters with badgeConfigState JSON parameters

    6. Close the dialog.

      Later, you will use a script to update this object's properties after the data resource loads.

  3. To set the badge config to the object just created, in the Content tree, select the Carousel component.

    1. On the Config tab for your Carousel component, hover over the Badge configuration property and select the Bind data or use scripts icon.

      [Omitted image "badge-bind-data-badgeconfig.png"] Alt text: Carousel Badge configuration showing the 3 parameters added and the pointer hovering over the Bind data or use scripts button

    2. In the Bind data to Badge configuration dialog, select the data type Client states.

    3. Select badgeConfigState (3), and to add it to the data output area, select the up arrow icon.

      [Omitted image "badge-02bind-data-badgeconfig.png"] Alt text: Bind data to Badge configuration dialog with Client states selected in Data types and badgeConfigState 3 highlighted with pointer hovering over up arrow button

    4. Select Apply.

      The badgeConfigState parameter should be added to the Carousel Badge configuration.

    [Omitted image "badge-config-final.png"] Alt text: Carousel Configure tab with the Badge configuration field displaying badgeConfigState in addition to the 3 previously added parameters

  4. Open the Edit client script dialog by selecting Add a new Edit client script.

    [Omitted image "badge-edit-clientscript01.png"] Alt text: Pointer hovering over Add new plus sign button and Edit client script dialog that appears when Add new button is selected

  5. To create a client script that updates the badgeClientState "label" parameter value to the number of items in the Carousel, enter: api.setState(badgeConfigState, {...api.state.badgeConfigState, "label": count: ${api.data.look_up_multiple_records_1.results.length}});

    [Omitted image "badge-edit-clientscript04.png"] Alt text: Edit client script dialog with client script added

  6. Add an event to the data resource so that your client script triggers whenever the data resource is updated.

    1. In the bottom left, select the data resource Look up multiple records 1 > Events tab.

      [Omitted image "badge-edit-dataresource01.png"] Alt text: Pointer, in the Data and scripts section, hovering over the Look up multiple records 1 data resource and Edit Look up multiple records 1 dialog Events tab selected

    2. Select Add event mapping, select Data Fetch Succeeded, and select Continue.

    3. Select Add handler, scroll down, and select the new client script you created, and select Continue.

      [Omitted image "badge-choose-eventhandler.png"] Alt text: Dialog for adding the New client script 1 event handler

    4. When to trigger should be set to Always.

    5. Select Continue.

    6. Select Add and close the Edit dialog.

  7. In the upper right corner, select Save > select the Preview dropdown arrow > Open URL path.

    [Omitted image "badge-final01.png"] Alt text: Final display showing the Title followed by count: 12

    The Title of your carousel should have a badge count followed by the number of carousel items.

Parent Topic:Learn components by example

Keywords UIBUI BuilderCarouselComponents
Search documentation
Search document titles and file paths on the australia branch