Cb Substitions - using "if" to compare two field values

4 years 10 months ago #312702 by rgarderet
Hello,
I am using the "if" substitution in some text at the top of a list (in the description field). I would like to display text based on comparing two field values from a user.

The following works:
[cb:if cb_requests_count="5"]You have requested 5 connections, which is the maximum allowed at any one time.etc...

but I would like to compare it to a user-specific field value, not "5" as in:

[cb:if cb_requests_count=cb_max_allowed]You have requested [cb_max_allowed] connections, which is the maximum allowed at any one time... etc

This isn't working, and I'm not sure if its just syntax that is not allowed, or if my field types are wrong. (cb_max_allowed is a value from a drop-down menu that I am setting depending on how many I want to give them).
Do you have any insights or alternative suggestions?

Many thanks,
Remy.

Please Log in to join the conversation.

4 years 10 months ago #312711 by krileon
The IF substitutions can't compare field value to field value. It's something we're looking into improving in a later release. Likely will be done by just supporting nested substitutions in it (e.g. [cb:if cb_requests_count="[cb_max_allowed]"]) like with parser substitutions in CB Auto Actions. For now easiest way to do this is probably a Code field using CB Code Field with the below code.

return ( (int) '[cb_requests_count]' == (int) '[cb_max_allowed]' ? 1 : 0 );

Then you'd just IF substitution against the code field against a value of 1 (maxed reached) or 0 (max not reached).


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

4 years 10 months ago #312720 by rgarderet
Hi Kyle,
Thanks very much for the fast response, as well as the excellent suggestion to use code. I will implement it that way.
Best regards,
Remy.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.238 seconds

Facebook Twitter LinkedIn