Skip to Content Skip to Menu

Increment a User Field

  • Robcey
  • Robcey
  • OFFLINE
  • Posts: 9
  • Thanks: 0
  • Karma: 0
8 years 9 months ago #268520 by Robcey
Increment a User Field was created by Robcey
Joomla! 3.4.3 Stable
CB 2.0.10

Hi Team,

I have made a User field Integer.
I would like to know how I can have the User Field automagically incremented on the creation of a new CB user with the value of the highest number from all old/existing users + 1.

I tried doing this with a CB Auto, but, I don't know how to seed the number from the old/existing users.

For example:
Existing users
User 1
User 2
User 5

Creating a new user would result in:
User 6

Any help appreciated.

Regards
Rob

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 68605
  • Thanks: 9108
  • Karma: 1434
8 years 9 months ago #268528 by krileon
Replied by krileon on topic Increment a User Field
You'll probably need to use a Query action for best results since you need the previous users value. The below usage should work fine.

Global
Triggers: After New User, After User Registration
Type: Query
User: Automatic
Access: Everybody
Action
Query:
Code:
UPDATE `#__comprofiler` SET `FIELD_NAME` = ( ( SELECT `FIELD_NAME` FROM `#__comprofiler` ORDER BY `FIELD_NAME` DESC LIMIT 1 ) + 1 ) WHERE `id` = '[user_id]'

Replace FIELD_NAME with the actual name of your integer field. CB already provides an incrementing ID though in the form of user_id so depending on your needs you may not exactly need this usage.


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.

  • Robcey
  • Robcey
  • OFFLINE
  • Posts: 9
  • Thanks: 0
  • Karma: 0
8 years 9 months ago #268615 by Robcey
Replied by Robcey on topic Increment a User Field
Hi Kyle,
Thanks for the response but I think I'm going around in circles.
It seems that the triggers are not firing.

To make sure I'm going to the correct area...
I'm navigating to CB --> Plugin Management --> CB Auto Actions

I created the Auto Action for the Field
The Triggers were not in the drop down list, so I just entered the values provided. But this didn't update the User Field.
I put in a Trigger for "GroupJive After Create User" to test if the trigger would fire.
When I add a new Group Jive User the trigger fired ad failed because the table wasn't available and therefore showed that the trigger was firing.

This is the Action Code:
UPDATE `#__comprofiler` SET `cb_sponsorid` = ( ( SELECT `cb_sponsorid` FROM `#__comprofiler` ORDER BY `cb_sponsorid` DESC LIMIT 1 ) + 1 ) WHERE `id` = '[user_id]'

I tested the SELECT on the database and it retrieves the correct data.

This then brings me back to my original question of what the Trigger should be on the creation of a CB User.

Sorry if this is a really dumb question, but I cannot find another trigger suggestion in the Forum (perhaps incorrect search?) that is the most appropriate when the CB User record is created.

TIA
Rob

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 68605
  • Thanks: 9108
  • Karma: 1434
8 years 9 months ago #268633 by krileon
Replied by krileon on topic Increment a User Field
Those triggers won't work if you directly copy and paste. You need to select them. If they're not there then you may have an out of date CB Auto Actions and should ensure you're using CB Auto Actions 6.3.1. It's not going to do anything with the wrong triggers selected. The triggers provided are for frontend and backend registration of a user.


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.

  • Robcey
  • Robcey
  • OFFLINE
  • Posts: 9
  • Thanks: 0
  • Karma: 0
8 years 9 months ago #268694 by Robcey
Replied by Robcey on topic Increment a User Field
Hi Kyle,

A step closer.

I deleted the older plugin and uploaded 6.3.1, then deleted the old triggers and recreated selecting the trigger names.

The triggers are now firing, but, now getting the following error?

Sorry for the continued questions, but, I'm clearly making a mistake that isn't obvious to me? I would appreciated your help... hopefully the last question.

Regards
Rob

1093 You can't specify target table 'jos_comprofiler' for update in FROM clause SQL=UPDATE `jos_comprofiler` SET `cb_sponsorid` = ( ( SELECT `cb_sponsorid` FROM `jos_comprofiler` ORDER BY `cb_sponsorid` DESC LIMIT 1 ) + 1 )

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 68605
  • Thanks: 9108
  • Karma: 1434
8 years 9 months ago #268698 by krileon
Replied by krileon on topic Increment a User Field
The below should work.

Code:
UPDATE `#__comprofiler` SET `FIELD_NAME` = ( SELECT `next` FROM ( SELECT ( MAX( `FIELD_NAME` ) + 1 ) AS next FROM `#__comprofiler` WHERE `id` != '[user_id]' ) AS cb ) WHERE `id` = '[user_id]'


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.

Moderators: beatnantkrileon
Powered by Kunena Forum

Facebook Twitter LinkedIn