Skip to Content Skip to Menu

🌲 Merry Christmas! Great savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2024!

[SOLVED] CB Auto Action to update a field in another table of the DB

  • ricco1
  • ricco1
  • OFFLINE
  • Posts: 310
  • Thanks: 8
  • Karma: -7
9 years 3 months ago - 9 years 3 months ago #269829 by ricco1
Hi,

Could you tell me a CB Auto Acton to update a field which not in the CB or CBSubs tables but is in another table of the same DB.

Let's say I have a CB text field called cb_my_cb_field and its value is getting changed on CBSubs plan change. Then if I have another field which stored in a table which is not in the CB or CBSubs tables how to update its value to be always the same as the cb_my_cb_field?

Thank you,
Best regards,
ricco
Last edit: 9 years 3 months ago by krileon.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48630
  • Thanks: 8307
  • Karma: 1446
9 years 3 months ago #269832 by krileon
Use a Query action then do an update or insert query as needed to push data from 1 table to another. CB Auto Actions can even do this to external databases. Using substitutions you can substitute in your field value for your query. Typically you'll want to do this on the following triggers.

onAfterUpdateUser, onAfterUserUpdate, onAfterNewUser, onAfterUserRegistration

Those triggers will cover profile update and registration for both frontend and backend.


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.
The following user(s) said Thank You: ricco1

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

  • ricco1
  • ricco1
  • OFFLINE
  • Posts: 310
  • Thanks: 8
  • Karma: -7
9 years 3 months ago #269879 by ricco1
Hi,

CB Auto Action is the greatest.

I've done it (hopefully), here is how:

I have a CB field called e.g. "cb_vip", the value of which is changed to 1 on VIP plan subscription.

Then I've made a CB Auto Action for it like so:

Type: Field
Trigger: Before Draw Subscription
User: Automatic
Access: Everybody
Conditional: [cb_vip] Empty
Action:
Field [cb_vip]
Operator Set (Field=Value)
Value 0

Then I've made another CB Auto Action:

Type: Query
Trigger: Before Draw Subscription
User: Automatic
Access: Everybody
Action: Query:
Code:
UPDATE `#__myothertable` SET `vip_222` = (SELECT `cb_vip` FROM `#__comprofiler` WHERE `#__comprofiler`.`user_id` = `#__myothertable`.`222_id` AND `#__comprofiler`.`cb_vip` = 1); UPDATE `#__myothertable` SET `vip_222` = 0 WHERE `vip_222` != '1';

Thank you CB Auto Action and god bless you,
Regards,
ricco

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

  • nant
  • nant
  • OFFLINE
  • Posts: 12339
  • Thanks: 1467
  • Karma: 877
9 years 3 months ago #269886 by nant
Not sure is

Trigger: Before Draw Subscription

is the proper trigger to use.

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

  • ricco1
  • ricco1
  • OFFLINE
  • Posts: 310
  • Thanks: 8
  • Karma: -7
9 years 3 months ago #269891 by ricco1
Hi Nick,

Why do you think so?

I've tried User State Change but its not working.

Do you think I should used them both or any other than Before Draw Subscription trigger?

Thank you,
Regards,
ricco

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48630
  • Thanks: 8307
  • Karma: 1446
9 years 3 months ago - 9 years 3 months ago #269905 by krileon
That's not the correct trigger to be using. That trigger is fired when the subscription is displayed. Doing an update query every time a subscription isn't good for performance. You should be using the following usages to act on subscription state change.

Plan Active
Triggers: onCPayUserStateChange
User: Automatic
Access: Everybody
Conditional 1: [var3] Equal To PLAN_ID_HERE
Conditional 2: [var2] Equal To A

Plan Expired
Triggers: onCPayUserStateChange
User: Automatic
Access: Everybody
Conditional 1: [var3] Equal To PLAN_ID_HERE
Conditional 2: [var2] Equal To X

If it's a free lifetime plan you're acting on then ensure it's configured to create subscriptions within CBSubs > Settings > Global.

However, if you're doing this on subscription state change it maybe better to just use CBSubs SQL Actions as all you'll need to supply is the query.

If the field value is changed manually then the triggers in my previous reply would be more ideal.


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.
Last edit: 9 years 3 months ago by krileon.
The following user(s) said Thank You: ricco1

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

Moderators: beatnantkrileon
Powered by Kunena Forum