Return key from filtered variable

I’m a WeWeb noob, so this is probably a very basic question but I can’t seem to figure it out.
I have created a list of variables that contains credential types, along with an associated colour for each type of credential. How can I return the colour value when a certain type is active.

The first screenshot shows that I have bound the elements background colour to the collection “Cred Types”

I’ve then added a filter to return the type of cred the current item is.
This is working but I now need to return the variables key “Colour” #FFBC9B but don’t know how to retrieve it from here.

You can use the getKeyValue formula or the JavaScript dot (.) notation to select a key inside an object :wink:

Thanks for getting back to me Quentin, but I think I’ve butchered it :roll_eyes:.

Is the filtered removed when getKeyValue is used?

My bad, you should keep your filter as is. Then, where you want to display the color, you should use the getKeyValue formula on the filtered object.

Sorry @Quentin, I’m still screwing it up.

I’ve applied the filter and used getKeyValue but it’s giving me the error that the First parameter should be an object. I’m clearly not using it correctly.

type in your object is a string, you should use the formula on the parent object, like so getKeyValue(item.data, 'colour')

Based on the image you first attached, you can try to switch to Javascript (on the Formula dropdown) and do [Cred Types][0].colour ([Cred Types] should be the green variable. The braces are just for illustration purposes.)

This should return #FFBC9B

I’m not really sure whether this is an array, looks like it might be. If it is an object structured like that, then you might try [Cred Types]['0'].colour

Thanks for replying @Quentin & @Broberto.

@Broberto, [Cred Types]['0'].colour didn’t work for me.

I should have mentioned earlier that I have a variable collection for the cred_types which I want to cross reference.

I’m basically populating the table with credentials.
Each credential has a cred_type.
I need to cross reference that cred_type with the variable collection and return the variable’s key “colour”

I hope it makes sense.

For anyone who encounters this issue, I managed to resolve it with the following.

1 Like