Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

[SOLVED] CB Auto Action - Field substitution based on REGEX

  • nijan
  • nijan
  • OFFLINE
  • Posts: 108
  • Thanks: 1
  • Karma: 0
11 years 7 months ago - 11 years 7 months ago #222670 by nijan
Hello,

I would like to create an action after Profile Update.
Is it possible to put a REGEX in the field action value ?

If yes ... what is the syntax (delimiter) ?

Thanks !
Last edit: 11 years 7 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • nijan
  • nijan
  • OFFLINE
  • Posts: 108
  • Thanks: 1
  • Karma: 0
11 years 7 months ago #222673 by nijan
Hello,

Suppose I have a multicheckbox [cb_variable] that contains Value1|*|Value2|*|Value3
Is it possible to replace field by Value1|*|Value2 ?

If yes how can I fill the value ? [cb_variable(1)] + [cb_variable(2)] ?

Thanks !

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48459
  • Thanks: 8280
  • Karma: 1443
11 years 7 months ago #222703 by krileon
You can't use REGEX in a value. You can combine substitutions though. Example as follows.

Field: Text Field
Operator: Set
Value: [cb_fieldname1] [cb_fieldname2]

It does not do math either so don't try to use a + expecting it to add the 2 values as it'll just add the + as part of the value. If you need complex calculations either pre-calculate the new value with a CB Query Field and set the field to that query fields value or use a Query action and directly change the value via database queries.


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 or Create an account to join the conversation.

  • nijan
  • nijan
  • OFFLINE
  • Posts: 108
  • Thanks: 1
  • Karma: 0
11 years 7 months ago #222724 by nijan
Hi Krileon,

Thanks for your answer. Query action seems to work.
I only need now to substring my [cb_field] before updating my table (REGEX or each other substring solution).

--> Example input before update cb_field = Value1|*|Value2|*|Value3|*|Value4

I do my REGEX to only kept the 2 first value --> Value1|*|Value2

--> Example input before update cb_field = Value1|*|Value2|*|Value3|*|Value4|*|Value5

I do my REGEX to only kept the 2 first value --> Value1|*|Value2

Suggestion to do that ?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48459
  • Thanks: 8280
  • Karma: 1443
11 years 7 months ago #222771 by krileon
It doesn't do that. It doesn't apply logic to substitutions. You'll need to use CB Query Field to format the field value using database functions then substitute the query field in as its value or just use a Query action to adjust the field value using database queries and using database functions to format it.


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 or Create an account to join the conversation.

  • nijan
  • nijan
  • OFFLINE
  • Posts: 108
  • Thanks: 1
  • Karma: 0
11 years 7 months ago #222859 by nijan
Hi Krileon,

I have exactly what I want !

For your info I create a function in mysql :

CREATE FUNCTION SPLIT_STR(
x VARCHAR(255),
delim VARCHAR(12),
pos INT
)
RETURNS VARCHAR(255)
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos),
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1),
delim, '');

After that in CB Auto Action I have the following Query to only keep the 2 first selected items of a Mutliple Check Box :

UPDATE `vksup_comprofiler` SET `cb_languesparlees` = CONCAT(SPLIT_STR(`cb_languesparlees` , '|', 1),'|*|',SPLIT_STR(`cb_languesparlees` , '|', 3));

It seems to work perfectly !

You can close this issue and many thanks for the time you spend to answer to our topic !
The following user(s) said Thank You: krileon

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum