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] Auto Action Code or Query? What's wrong?

11 years 4 months ago - 11 years 4 months ago #228755 by zerogravita
Hello,
I want to update a field in comprofiler table when the request of connection made by a user is accepted. To better explain:
I have three type of usergroup: Volunteer, Association and Volunteer-not-confirmed.
When a Volunteer-not-confirmed ask for connection to an Association and the association accept his request, I want to update the custom field in comprofiler table [cb_assoid] with the value of the [cb_assoid] of the Association.
Then when the Volunteer-not-confirmed do the login and the field [cb_assoid] is no more empty, with an other auto action I change his usergroup from Volunteer-not-confirmed to Volunteer.
That's all.

I try CODE auto action with this params:

Type: code
Trigger: onAfterAddConnection
Access: Volunteer-not-confirmed
Method: PHP create function
Code:
Code:
$user = & JFactory::getUser(); $user_id = $user->id; global $_CB_framework, $_CB_database; $query = "SELECT memberid FROM r0sdt_comprofiler_members WHERE referenceid=$user_id AND accepted=1 AND pending=1"; $_CB_database->setQuery( $query ); $member_id =$_CB_database->loadResult(); $query2 = "SELECT cb_assoid FROM r0sdt_comprofiler WHERE id=$member_id "; $_CB_database->setQuery( $query2 ); $cb_assoid =$_CB_database->loadResult(); $query3 = "UPDATE r0sdt_comprofiler SET cb_assoid=$cb_assoid WHERE user_id=$user_id"; $_CB_database->setQuery ($query3);

Return: Silent
But the field is not updated... even if in the debug all is ok...

Have any idea?
Last edit: 11 years 4 months ago by krileon.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48464
  • Thanks: 8280
  • Karma: 1443
11 years 4 months ago #228758 by krileon
Replied by krileon on topic Auto Action Code or Query? What's wrong?
The below should work for what you're wanting.

Type: Field
Trigger: onAfterAcceptConnection
User: Manually - Variable 2
Access: Association
Field: Your Field
Operator: Set
Value: [var1]

To explain the above when the Association user accepts a connection request it updates the field of the user requesting the connection with the user id of the association user.

You would then use this in your new usergroup action on login as follows.

Type: Usergroup
Trigger: onAfterLogin
Access: Volunteer-not-confirmed
Conditional: [cb_yourfield] Not Empty
Mode: Replace Usergroup
Groups: Volunteer

The above after a not confirmed volunteer logs in it'll check if your field has a value. If it does it'll replace their current usergroups with the Volunteer usergroup (this was you get rid of the not confirmed volunteer usergroup).


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.

11 years 4 months ago #228764 by zerogravita
Replied by zerogravita on topic Auto Action Code or Query? What's wrong?
Thanks Krileon for your fast answer,
but I still have difficulties to make work the first autoaction...
You'll find a screenshot of my settings.
I'll try with Value: [var1] or Value: [cb_assoid] or Value: [var1_cb_assoid] - that is the real field I want to update for the user who belong to Volunteer-not confirmed usergroup.
But nothing happens in my db.
The field you see with label "Id Associazione" is the cb_assoid in comprofiler table.

Any suggestion?
Thanks

LAura
Attachments:

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48464
  • Thanks: 8280
  • Karma: 1443
11 years 4 months ago #228770 by krileon
Replied by krileon on topic Auto Action Code or Query? What's wrong?
Whoops, forgot access check applies to the User. Try the below Query action instead.

Type: Query
Trigger: onAfterAcceptConnection
User: Manually - Variable 1
Access: Association
Code:
UPDATE `#__comprofiler` SET `cb_assoid` = '[var1]' WHERE `id` = '[var2]'


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.

11 years 4 months ago #228776 by zerogravita
Replied by zerogravita on topic Auto Action Code or Query? What's wrong?
Almost.... but not success yet...

Finally the update works, but now set the userid of the Association in the field cb_assoid of the Volunteer, while I want to set the cb_assoid of the Association in the field cb_assoid of the Volunteer...

Example: some value of the table comprofiler:

id: 394 - userid: 394 - cb_assoid: 5001 - Usertype: Association
id: 937 - userid: 937 - cb_assoid: NULL - Usertype: Volunteer-not-confirmed


After the autoaction I want that in the row with id=937 the field cb_assoid is set =5001 (the cb_assoid of the Association that accepted the connection).

With your code now I have cb_assoid= 394 (that is the userid of the association).

:) Thanks!!!

LAura

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48464
  • Thanks: 8280
  • Karma: 1443
11 years 4 months ago #228784 by krileon
Replied by krileon on topic Auto Action Code or Query? What's wrong?
Change `cb_assoid` = '[var1]' to `cb_assoid` = '[cb_assoid]' and that should give you what you're wanting.


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