How to extract data from one field, parse it, and store it in 4 other fields

3 years 6 months ago #320697 by pgay@patrickgay.com
I had a chance to try to make this work but have hit a snag.

The checkbox field has 4 options which will be stored as 1, 2, 3, and/or 4 depending on the checkboxes selected.

In the database, it's stored as 1|*|2|*|3|*|4.

I need a "value" statement that will read the CHECKBOX field, parse the data, and based on what it finds, store a text value in a textfield.

My Guess: (I know this is wrong - can't figure out how to parse the data stored in the checkbox field)
Value Row 1: [cb:if LEFT(cb_volunteertype,1)=~"1"]Application Processor[cb:else]NULL[/cb:else][/cb:if]
Value Row 2: [cb:if MID(cb_volunteertype,5,1)=~"2"]Transporter[cb:else]NULL[/cb:else][/cb:if]
Value Row 3: [cb:if MID(cb_volunteertype,9,1)=~"3"]Fosterer[cb:else]NULL[/cb:else][/cb:if]
Value Row 4: [cb:if MID(cb_volunteertype,13,1)=~"4"]Other[cb:else]NULL[/cb:else][/cb:if]

For example,
A user selects volunteer type 1 and 3. The cb_volunteer_type field is now set to 1|*|3.
When the CB Auto Action is done, this would be the final result:
cb_volunteer_type_1 = 1
cb_volunteer_type_2 = 3
cb_volunteer_type_3 = null
cb_volunteer_type_4 = null

The code above assumes I'm trying to read one checkbox field and store data in another checkbox field, but what I'm trying to do is different, see above.

Please Log in to join the conversation.

3 years 6 months ago #320709 by krileon
See my example provided to you earlier.

www.joomlapolis.com/forum/153-professional-member-support/242934-how-to-extract-data-from-one-field-parse-it-and-store-it-in-4-other-fields?start=0#320636

Replace the 1 with whatever value you want and the target field with whatever field you want to store it to. In your case an integer field or text field would be needed since you're needing to store something other than a 0 or a 1. CB Auto Actions can't do a NULL store with a Field action you'd have to directly query the database to do that.

I need a "value" statement that will read the CHECKBOX field, parse the data, and based on what it finds, store a text value in a textfield.

The =~ operator is a REGEXP operator so you can use whatever REGEX you like to match values. If you need PHP you can try using Format Functions as described under the Parameters tab.

You can also just use a Query action and push the data to Moodle directly as long as there's a reference id linking the two databases together. I sill recommend just using separate fields for this. If you need custom values for a checkbox field use a multi-checkbox with only 1 value, a radio field, or a dropdown 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.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.158 seconds

Facebook Twitter LinkedIn