Toggle value true if ObjectID in the table?


I have a list of subjects and a table called “Interests” in my database. User can “add to interests” any of those subjects. How to configure my toggle value in toggle list item so it’s set to false when user hasn’t added this subject to interests, and true if he has (objectID is in database)?

Hi, you could use the IS_IN_ARRAY formula function (documentation)

If you are repeating the items, you can set the toggle value to IS_IN_ARRAY(data.Interests, current.objectId).

Hi, sorry that I wasn’t clear enough. I also wanted to bind toggle value to this formula, but I just didn’t find a “formula” option here. Is it because of true/false value type? And how to assign the formula in this case?

Hi, apologies for the faulty instructions. :sweat_smile:

I forgot that it’s not currently possible to bind the toggle value to a formula, since a formula binding will only work in one direction. The value of the toggle could in theory be taken based on a formula, but going to the other direction, the toggle won’t know what resource it’s supposed to update because the original source has been “obscured” by the formula.

However you can bind the toggles to properties of items in a repeat, so if the items have a true/false property favorite, it works. :slight_smile:

Instead of using a toggle you could also make a custom component such as a star button, the styles of which would be set based on IS_IN_ARRAY(data.Interests, current.objectId), and on the Component Tap event the objectId would be added to or removed from the user’s favorites list, resulting in the styles of the component changing.

Hi, thank you :slight_smile:

Now I am trying it with icon instead of toggle. And I am not repeating my component, so I cannot use “current.objectId”.
What should I do in this case? I’ve tried to use this formula with Page Parameter, but it doesn’t work. The icon does not recognize whether objectId in the table or not, so it’s always “heart-o”. And something is wrong with my logic too, it just creates new objectId’s, but doesn’t delete existing ones.

Here is the logic:

Hi, I’ve received the warning you’re getting with the icon names before, but the formula still worked, so I don’t think the issue is with that unless there’s a new bug – I’ll check that out just in case.

Also the flows look like they should work – in this situation I would try to use the debugger’s State tab to check that all your variables are really getting the values that you expect them to, so you can pinpoint in which step it fails.

Thanks, Mari.

I think I figured it out, now I want to use these statements in my formula.

IS_IN_ARRAY_BY_KEY(data.Interests1, “InterestedSubject”, params.SubjectName)
IS_IN_ARRAY_BY_KEY(data.Interests1, “Email”,

How can I put both of these conditions in one IF statement?
I want to have something like this:

IF((Condition 1 AND Condition 2), “heart”, “heart-o”)

Hi, great! You can use the && operator to replace AND in your formula.

The basic logic operators you can use in formulas are && (AND), || (OR) & ! (NOT) :slight_smile:

Thank you! Really appreciate your fast replies :slight_smile:

1 Like