Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Dynamic Data Binding Issue: Same Task Number on All Cards

ronro2
Tera Contributor

Hey guys! 

I really wonder what I'm doing wrong, as I've followed this Youtube tutorial thoroughly. Watch from 5:27 to understand where my issue starts.

I am trying to show information about specific tasks, but it doesn't matter which card I open up, the task number is always static, giving me this very task number: RB0054179 (no matter what button I click in whatever card). 

 

I always get this same information: 

ronro2_0-1764345512809.png

 

This is the "Bind data to content" information box: 

ronro2_1-1764345673921.png

ronro2_2-1764345726177.png


The binded data source is based on a single lookup record type in my case as well. 

 

What do you think I am missing? What could be possible issues? 

Greetings!

1 ACCEPTED SOLUTION

You have to first create a client script in the bottom left and then 

lauri457_0-1764848636267.png

when you're selecting a handler for an event they are at the bottom of the list.

lauri457_1-1764849073115.png

But you can use the no-code "update client state parameter" instead of client script as long as you are binding to the component property from state

View solution in original post

8 REPLIES 8

lauri457
Giga Sage

I didn't watch the video but you shouldn't necessarily have another data resource to get the record for your modal. You can pass whatever info you need inside your repeater as part of the data array. Meaning if you need number, state whatever you get that in your lookup and pass it to the repeater. That way the nth component inside the repeater can reference the repeater data at index n like you have done.

 

Then with your button component, you should bind an event handler(s) to the button clicked event. Then you can pass some of the information to the modal with the handler. And whatever else you need in the modal I would store in a client state parameter and bind to the modal contents.

 

So you would have something like this

lauri457_1-1764814398123.png

Client script "Update state params":

/**
*  {params} params
*  {api} params.api
*  {any} params.event
*  {any} params.imports
*  {ApiHelpers} params.helpers
*/
function handler({api, event, helpers, imports}) {
   api.setState("number", event.context.item.value.number.displayValue)
   api.setState("sysid", event.context.item.value.sys_id.displayValue)
}

Binding state to modal content property for example:

/**
 *  {params} params
 *  {api} params.api
 *  {TransformApiHelpers} params.helpers
 */
function evaluateProperty({
    api,
    helpers
}) {
    return `${api.state.number} sysid is ${api.state.sysid}`;
}

lauri457_0-1764814379973.png

If you instead want to bind from another data resource to the modal properties then you need to also refresh that data resource with the button clicked event.  

ronro2
Tera Contributor

@lauri457 I am trying to work things out with your help. But I cannot find any handler called "Execute - Client Script". 

I can only find these handlers: "Execute" and "Update client state parameter".

You have to first create a client script in the bottom left and then 

lauri457_0-1764848636267.png

when you're selecting a handler for an event they are at the bottom of the list.

lauri457_1-1764849073115.png

But you can use the no-code "update client state parameter" instead of client script as long as you are binding to the component property from state

ronro2
Tera Contributor

@lauri457 OH YES IT WORKS NOW! YOU ARE A HERO.