[SOLVED] Can I use CB Auto Actions to calculate?

1 week 6 days ago - 1 week 5 days ago #316179 by dklotz
Hi there!

I'm fiddling around with CB Auto Actions, trying to calculate a field value. What I've done so far doesn't work tho.

There are three fields:
cb_width
cb_length
cb_area

What I'm trying to do is calculate the cb_area value.
It's a simple multiplication: [cb_width] * [cb_length] = [cb_area]

Please, can someone explain how to do this with CB Auto Actions?
If it is possible at all...
Would be great to have some step-by-step instructions as I'm completely new to CB Auto Actions and I'm quite puzzled how to get this to work.

Thanks for any advice!

Dirk
1 week 6 days ago - 1 week 6 days ago #316183 by krileon
Yes, it can be used for math. You need to use the math format function. You can enable format functions under the Parameters tab. Details on how to use format functions can also be found under the Parameters tab. You'd likely need to do this anytime profile is updated and after registrations. So the following for example should work.

Global
Triggers: onAfterUserRegistration, onAfterNewUser, onAfterUpdateUser, onAfterUserUpdate
Type: Field
User: Automatic
Access: Everybody
Action
Field: cb_area
Operator: Set
Value:
[cb:parse function="math"][cb_width] * [cb_length][/cb:parse]
Parameters
Format Functions: Yes

You don't need CB Auto Actions for that though. You should be able to just use a Code field provided by CB Code Field and do your math entirely with some PHP. Example as follows.

return (int) '[cb_width]' * (int) '[cb_length]';

As long as you don't need the value stored in the database directly this should be sufficient for your needs, but if you need the value stored (e.g. searching purposes) you'll need to use CB Auto Actions.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Templates - CBSubs - Hosting - Forge - Incubator - GroupJive
--
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 EST to 4:00 PM EST. 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: dklotz
1 week 6 days ago #316191 by dklotz
Krileon!

Thank you so much for your quick reply!
I followed your explanation and wohoo - it works! (of course :) )

The other way you mentioned - using a CB Code Field - seems to be too difficult for me.
Unfortunately I have no idea how to start on this. Anyway.

Thanks again for your help!

Best Regards,
Dirk
1 week 6 days ago #316192 by dklotz
Uhm. Sorry, but I got another question. The math only works in frontend. When I update the user data in backend as an administrator, the area-field does not change. Please, can you explain which trigger is to be used for this?
Thanks!
1 week 6 days ago #316197 by krileon
Ensure you've used all 4 triggers. 2 of them are for frontend and 2 are for backend. The frontend and backend are as follows.

Frontend: onAfterUserRegistration, onAfterUserUpdate
Backend: onAfterNewUser, onAfterUpdateUser


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Templates - CBSubs - Hosting - Forge - Incubator - GroupJive
--
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 EST to 4:00 PM EST. 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: dklotz
1 week 6 days ago #316205 by dklotz
Okay, got it! THANK YOU!
Moderators: beatnantkrileon
Time to create page: 0.422 seconds

Facebook Twitter LinkedIn