Skip to Content Skip to Menu

How to assign value to CB Text Field in Auto Action Type Code after JSON decode?

  • MMDoege
  • MMDoege
  • OFFLINE
  • Posts: 98
  • Thanks: 3
  • Karma: 0
6 years 8 months ago #302323 by MMDoege
Hello,
for demo purposes we've temporarily set 3 fields as type "Code".
Goal is to fetch JSON (single array) via API call, decode and trim it to CB field values. This demos screenshot 1 (for CB field ..._title) and 2 (frontend view).
This works properly. Return displays values correctly.
Field type of these 3 fields is "Text" when in normal operation, not code

However, this fetch and decoding operation is required only when an specific ID field gets updated by user.
In addition values fetched from JSON have to be saved to user profile to be become searchable.

We think an Auto Action is appropiate here (screenshot 3):
TRIGGER: onAfterUpdate
CONDITION: ID field not empty
ACTION: Method=PHP
OUTPUT: None (at least no display required here)

Screenshot 3 has an DB query that did not at all. Fields remain blank.

Now, how can we just simply assign a value to a CB field, like:
[cb_youtube_video_title]=$result;
which would save value to #_comprofiler table.

Please assist.

Thank you in advance.
Regards. Michael.
Attachments:

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48444
  • Thanks: 8279
  • Karma: 1443
6 years 8 months ago #302345 by krileon
Code actions have direct access to the $user object. You can set a field and store it using the below.

Code:
$user->set( 'FIELD_NAME', VALUE ); $user->store();

This does not fire profile update triggers so it won't get stuck in a loop by doing this. If you're changing another action after this action be sure to enable reload user under Parameters in the action after this one so it sees your user object update.


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: MMDoege

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

  • MMDoege
  • MMDoege
  • OFFLINE
  • Posts: 98
  • Thanks: 3
  • Karma: 0
6 years 7 months ago #302378 by MMDoege
Thank you Kyle for your quick response.

I've updated the code, and ... nothing has been written/updated to DB. Fields remain empty as you're saying: "This does not fire profile update triggers"
So how we get the DB CB fields updated then? I'm afraid I've not got the point here. reload user set to yes.

Thank you,
Regards, Michael.

PS: Code in Code Field works properly, DB got updated.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48444
  • Thanks: 8279
  • Karma: 1443
6 years 7 months ago - 6 years 7 months ago #302393 by krileon

I've updated the code, and ... nothing has been written/updated to DB. Fields remain empty as you're saying: "This does not fire profile update triggers"
So how we get the DB CB fields updated then? I'm afraid I've not got the point here. reload user set to yes.

PS: Code in Code Field works properly, DB got updated.


I don't understand. These two statements are conflicting. You can't have your code action which is acting on the after profile update trigger fire the profile update trigger. That creates an infinite loop and would crash.


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: 6 years 7 months ago by krileon.

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

  • MMDoege
  • MMDoege
  • OFFLINE
  • Posts: 98
  • Thanks: 3
  • Karma: 0
6 years 7 months ago #302407 by MMDoege
Hello,

we have tested our PHP script in a CB Code Field. In this case Auto Action Code is unpublished of course.
PHP code in this field provides correct results and saves data to #_comprofiler. PHP code works properly.
When Auto Action Code is published involved fields are set to type "text field".
What we are looking for is to save data only when profile has been updated.
We understand from your comments that this is not possible via a Auto Action Code when updating values.

Thanks for your assistance.
Regards, Michael.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48444
  • Thanks: 8279
  • Karma: 1443
6 years 7 months ago #302418 by krileon
A code field should not be storing anything. You're causing A LOT of database stores, which will slow database access significantly. You need to handle storage with CB Auto Actions at specific cases like after a profile is updated and/or after a user registers. CB Auto Actions has a Code action where you can supply your PHP. If you want to keep the code field and store the code fields results then use a Field action and substitute in the code field when configuring the value to set into another field.


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: MMDoege

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

Moderators: beatnantkrileon
Powered by Kunena Forum