'In Microsoft Dynamics 365 F&O's X++, why doesn't this event reassign the value of CustTable.CustGroup?

I'm currently working my way through Event Handlers in D365 with Example.

As I understand this code:

class EventHandlerCustTable
{    
   
   [DataEventHandler(tableStr(CustTable), DataEventType::Inserted)]
   public static void CustTable_onInserted(Common sender, DataEventArgs e)
   {
       CustTable custTable = sender as CustTable;
       // 90 is the Customer group code for Intercompany Cutomer
       if(custTable.CustGroup=="90")
           
       {
           // 80 is the Customer group code for Other Customer
           custTable.CustGroup="80" ; 
           Global::error("Created Customer is an Intercompany Cutomer and will be added to the Customer Group Other Customer");
           
           // you can write your logic here.        
       }
 
      
   }
 
} 

... when the value of custTable.CustGroup is "90", the value should be reset to "80" and the error message should appear.

However, when I execute the code, the value is not changed. In fact, the screenshot of the article itself does not display this value as changed, though like my own local experience, the error message is in fact displayed.

So:

  1. Why doesn't the value change?
  2. How can we fix this?


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source