Is it possible to ‘setCustomAttribute()’ in ‘controller_action_postdispatch_’ observer?

Hi, I have an observer for ‘controller_action_postdispatch_myextension_saveUser’ event. This observer should set a custom customer attribute when the event is triggered.

This is my observer:

 $customer = $observer->getEvent()->getCustomer(); $customerId = $this->customerSession->getCustomer()->getId(); $customerData = $customer->getDataModel(); $customerData->setCustomAttribute('myattributecode', $customerId); $customer->updateData($customerData); $customer->save(); 

It is working when I observe the event ‘customer_save_after’ but I only need it when the controller_action event is triggered. In this case I get Error: Call to a member function getDataModel() on null.

Is there any way to set custom attribute in controller_action? Thank you very much

submitted by /u/hardy123480
[link] [comments]