Skip to Content Skip to Menu

🌟 CB Editor Assistant 1.0.0 is here! Discover our new AI Joomla Plugin that wrote its story! (and this banner!)
Start at just $12.50/month* or 💸 save 30% with our 🛍️ Intro Black Friday Offer for a lifetime*

Field Value replacement via Auto Action on every profile update/save?

5 years 2 months ago - 5 years 2 months ago #314257 by miervaldis
Hi, I can't seem to get Action Script working... Here's the scenario...

Every time a user saves changes to their profile, I want to update the values of two fields "firstname" and "lastname" with the current values of the fields "cb_role" and "cb_pseudonym", respectively.

On the Global tab, for trigger, I have "onAfterUserUpdate".
For conditions, I did not specify any.
For Actions, see the attached screen capture.
Nothing under Output.

Attachments:
Last edit: 5 years 2 months ago by miervaldis. Reason: rewrote for clarity

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48551
  • Thanks: 8291
  • Karma: 1445
5 years 2 months ago #314283 by krileon
That trigger only applies to frontend profile changes. If you're testing this in backend it'll appear to not work. For backend you'd need to also add the onAfterUpdateUser trigger to the auto action.

Name fields are also tricky. firstname, middlename, and lastname are merged together to form the name field. The name field is stored to Joomla _users. The firstname, middlename, and lastname are stored to _comprofiler. None of this join/split behavior is happening since you're doing a direct save, but if you don't you'd get stuck in a loop since non-direct saves will fire that trigger. Best I can suggest is you'll have to handle the entire behavior chain your self using a Query action and directly modifying the database instead. Example as follows.

Code:
UPDATE `#__comprofiler` SET `firstname` = '[cb_role]', `lastname` = '[cb_pseudonym]' WHERE `id` = '[user_id]'; UPDATE `#__users` SET `name` = '[cb_role] [cb_pseudonym]' WHERE `id` = '[user_id]';

Is there a reason you're copying those fields to the name fields? You can override a fields output using the Layout parameters to avoid having to handle double storage. To do this edit the firstname field then under Parameters > Layouts set "Profile Value Layout" to [cb:userfield field="cb_role" /] then edit lastname and set "Profile Value Layout" to [cb:userfield field="cb_pseudonym" /].


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.

5 years 2 months ago #314285 by miervaldis
This ended up being my workaround to avoid the need to hand-edit templates to display the information I wanted to show. Because the "view profile" view seems to be statically set to display [formatted name], but that is not what I want. It seemed simpler to force change the firstname and lastname values and thus utilize the templates as-built and make my design more future-proof.

I will try your suggested code and see how it goes.

Thank you!

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48551
  • Thanks: 8291
  • Karma: 1445
5 years 2 months ago #314286 by krileon
You can completely override what the formatname field displays using the Layout parameters as well. For example edit it and under Parameters > Layout set "Profile Value Layout" to [cb:userfield field="cb_role" /] [cb:userfield field="cb_pseudonym" /] to have those 2 fields display as its value. If displayed outside of profile you'll need to do the same for userlist view layout.


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.

5 years 2 months ago #314287 by miervaldis
This ended up being my workaround to avoid the need to hand-edit templates to display the information I wanted to show. Because the "view profile" view seems to be statically set to display [formatted name], but that is not what I want. It seemed simpler to force change the firstname and lastname values and thus utilize the templates as-built and make my design more future-proof.

I implemented the code you suggested and it works perfectly! Thank you for your assistance!
The following user(s) said Thank You: krileon

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

5 years 2 months ago #314289 by miervaldis
Sorry, but I am not sure where the Parameters you describe are located. Would you point me in the right direction?

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

Moderators: beatnantkrileon
Powered by Kunena Forum