Skip to Content Skip to Menu

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

Accessing the individual fields within a field group

  • Timpowwow
  • Timpowwow
  • OFFLINE
  • Posts: 9
  • Thanks: 2
  • Karma: 0
4 years 9 months ago #316981 by Timpowwow
Hello there!

I need to access the individual fields in a field group. In comprofiler table I see each field in the group is set to null, and the field group field has some kind of two-dimensional array.

My scenario; I have a group of students I want to book sessions with. The field group cb_sessions, contains fields: cb_student, cb_sessiondate, cb_sessionstart, cb_sessionend and cb_attended. I would like to trigger an action on the update of this field, cb_sessions, and send an email to the student using auto actions. I look at the fields for triggering and see only the nullified fields. Any suggestions would be helpful...

I would also like to filter out students in this field group, when using a userlist, so that students can only see their sessions that I have booked. Not every student's session.

Your help would be appreciated, again! :)
Thanks
Tim

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48622
  • Thanks: 8302
  • Karma: 1446
4 years 9 months ago #316989 by krileon
Field groups are stored in JSON columns as a JSON string. You can't apply normal field logic to them. So they have to be accessed in a different way and often you are not going to be able to filter on them like you would other fields. It is possible to search field group fields but you need to be using MySQL 5.7.8+ (MariaDB is not supported). If you have MySQL 5.7.8+ then you should be able to just mark the field as searchable like you would any other field.

As for accessing sub values inside of a field group field the substitutions for that are a bit tricky. Their format is as follows.

FIELD_NAME__INDEX__FIELD_NAME

The first field name is the name of your field group field. For example lets call it cb_fieldgroup. Next the index is the row in the field group field you want to access. The index always begins with 0. Finally the last field name is the name of the field in the field group field of the specified row that you want to substitute in. For example lets call this cb_text. This gives you the below.

cb_fieldgroup__0__cb_text

Used as a raw substitution you'd have the below.

[cb_fieldgroup__0__cb_text]

This should function anywhere substitutions are supported.


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.

  • Timpowwow
  • Timpowwow
  • OFFLINE
  • Posts: 9
  • Thanks: 2
  • Karma: 0
4 years 9 months ago #317001 by Timpowwow
Great thanks! Fully understood! Substitutions work fine!

But, how would I specify the index of the last item in the JSON string?

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48622
  • Thanks: 8302
  • Karma: 1446
4 years 9 months ago #317007 by krileon

But, how would I specify the index of the last item in the JSON string?

You would have to know what the last index is, but that does give me an idea to possibly implement another pseudo field for that. So you could do something like cb_fieldgroup__first__cb_text or cb_fieldgroup__last__cb_text. Have added a feature ticket for this.

forge.joomlapolis.com/issues/7873


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.

  • Timpowwow
  • Timpowwow
  • OFFLINE
  • Posts: 9
  • Thanks: 2
  • Karma: 0
4 years 9 months ago #317009 by Timpowwow
Hmm...wouldn't first always be index 0? Last would always be length - 1?

A change would be good, but I'm actually looking at stripping the JSON string, parsing it, and putting the individual fields into their own table. It's a bit of a nightmare...

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48622
  • Thanks: 8302
  • Karma: 1446
4 years 9 months ago #317013 by krileon
Yes, first is always 0. Last is not -1. Last is whatever the last row is. It increments up from 0. So if they've 10 rows the last row is index 9. All you're doing is accessing the array index of the stored JSON. Providing keywords for first, last, and maybe a few others is easier for users to use.

A change would be good, but I'm actually looking at stripping the JSON string, parsing it, and putting the individual fields into their own table. It's a bit of a nightmare...

Why? What purpose would there be to doing that?


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