web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Code stopped working after update

(0) ShareShare
ReportReport
Posted on by 313

Hello everyone,

I'm still looking into this issue, but I thought I would throw out this question here to see if anyone can point me in the right direction.

A while back, I created an extension of the insert method of a table and everything was working perfectly.  I put my code after the next Insert so that I could use some of the values to query other tables and get the info I need.

We have a company that helps with coding and they put in an update last week.  Since then, my code still gets hit, but when I hit a line that say
custAccount = this.SalesCustAccount

Now that SalesCustAccount is null when it wasn't before.

If I let everything finish, and the record gets inserted, SalesCustAccount is not null so it's almost as if now my code is running to early or something.

My gut says that other company (who created this table originally) made another extension and changed the code to fill the fields after mine?  Not sure if that even makes sense.

I'm about to step through the code and see if I can figure out where it's going and what it is doing but if anyone has a suggestion how I can troubleshoot this, or what could possibly be the issue, that would be great.

I know it's not easy without me providing code but I was just hoping someone would have seen this before.

I have the same question (0)
  • GirishS Profile Picture
    27,825 Moderator on at
    RE: Code stopped working after update

    Hi Andrew Huisman,

    Check whether there is onInserting or onInserted event handler was added.

    Also add SalesCustAccount to the info log to check whether it's actually null or not. Because there may be some refresh issues with debugger.

    Thanks,

    Girish S.

  • Andrew Huisman Profile Picture
    313 on at
    RE: Code stopped working after update

    Hi Girish,

    I'm not sure how to see what they did.  I may need to contact them.  The strange thing is that I stepped through the code and now the insert method on the table is running after my code when I clearly have the next call before my code....

    [ExtensionOf(tableStr(AMDeviceTable))]
    final class AMDeviceTableTableTCI_Extension
    {
        public void insert(boolean _setDeviceActive)
        {
            str                                         custAccount;
            str                                         custCountryCode;
            str                                         custCountryName;
            CustTable                                   custTable;
            LogisticsAddressCountryRegionTranslation    lacrt;
            AMDeviceTableMaster                         amDeviceTableMaster;
            AMDeviceRegistrationPlate                   amDeviceRegistrationPlate;
    
            next insert(_setDeviceActive);
    
            info(this.salesCustAccount);
            info(this.SalesCustAccount);
    
            custAccount = this.SalesCustAccount;
    
            select custTable
                where custTable.AccountNum == custAccount;
    
            if (custTable)
            {
                custCountryCode = custTable.PartyCountry;
            }
    
            select lacrt
                where lacrt.CountryRegionId == custCountryCode
                && lacrt.LanguageId == 'en-ca';
    
            if (lacrt)
            {
                custCountryName = lacrt.ShortName;
            }
    
            select amDeviceRegistrationPlate
                where amDeviceRegistrationPlate.Name == custCountryName;
    
            if (amDeviceRegistrationPlate)
            {
                
                select forupdate amDeviceTableMaster
                    where amDeviceTableMaster.MasterId == this.MasterId;
                ttsbegin;
                amDeviceTableMaster.RegistrationPlateId = amDeviceRegistrationPlate.RegistrationPlateId;
                amDeviceTableMaster.update();
                ttscommit;
            }
            
        }
    
    }

    Do you see or know any reason why that would happen?  I need my code to run after the original Insert method.....

  • Suggested answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: Code stopped working after update

    If your code wants to run after the insert method of the table then you need to write your logic on OnInserted event handler of the table.

    Thanks,

    Girish S.

  • Andrew Huisman Profile Picture
    313 on at
    RE: Code stopped working after update

    I've never done that before, can you tell me how?

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: Code stopped working after update

    Refer to the below code. Open your table >> Expand events node >> Select OnInserted event handler >> Right click copy event handler >> Create new class and paste the event handler code like below.

    [DataEventHandler(tableStr(TableName), DataEventType::Inserted)]
    public static void TableName_onInserted(Common sender, DataEventArgs e)
    {
        TableName tableName = sender as TableName;
        //here buffer tableName holds table field values where you can perform operations.
    
    }

    Thanks,

    Girish S.

  • Andrew Huisman Profile Picture
    313 on at
    RE: Code stopped working after update

    Hi Girish,

    I'm still working on this and can't get it working.  I do hit this code but the record hasn't technically been added to the table yet so I still can't get the info.  It doesn't make sense because it seems like this code should run when a record is inserted so I'm very confused.  I've been working on this now for a few days and still can't seem to find a way to get it to work correctly.

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: Code stopped working after update

    Can you share your code for onInserted event handler?

    Thanks,

    Girish S.

  • Alex VN Profile Picture
    1,994 on at
    RE: Code stopped working after update

    Hi,

    One thing you might check.

    Can you check if the inserted line to the database has SalesCustAccount or not? May be other extension is clearing SalesCustAccount before the insert call.

    As extension can not guarantee which extension run first so you might need to do debug and see the call stack to see if other customization is manipulating the data BEFORE your extension.

  • Andrew Huisman Profile Picture
    313 on at
    RE: Code stopped working after update

    Here you go,

    /// 
        ///
        /// 
        /// 
        /// 
        [DataEventHandler(tableStr(AMDeviceTable), DataEventType::Inserted)]
        public static void AMDeviceTable_onInserted(Common sender, DataEventArgs e)
        {
            str                                         custAccount;
            str                                         custCountryCode;
            str                                         custCountryName;
            CustTable                                   custTable;
            LogisticsAddressCountryRegionTranslation    lacrt;
            AMDeviceTableMaster                         amDeviceTableMaster;
            AMDeviceRegistrationPlate                   amDeviceRegistrationPlate;
            AMDeviceTable                               amDeviceTable = sender as AMDeviceTable;
    
            custAccount = amDeviceTable.SalesCustAccount;
    
            select custTable
                where custTable.AccountNum == custAccount;
    
            if (custTable)
            {
                custCountryCode = custTable.PartyCountry;
            }
    
            select lacrt
                where lacrt.CountryRegionId == custCountryCode
                && lacrt.LanguageId == 'en-ca';
    
            if (lacrt)
            {
                custCountryName = lacrt.ShortName;
            }
    
            select amDeviceRegistrationPlate
                where amDeviceRegistrationPlate.Name == custCountryName;
    
            if (amDeviceRegistrationPlate)
            {
                
                select forupdate amDeviceTableMaster
                    where amDeviceTableMaster.MasterId == amDeviceTable.MasterId;
                ttsbegin;
                amDeviceTableMaster.RegistrationPlateId = amDeviceRegistrationPlate.RegistrationPlateId;
                amDeviceTableMaster.update();
                ttscommit;
            }
        }

    The problem is that SalesCustAccount is null.  So it's not that this event handler isn't working right, it's that the information is not all filled out.  But when the record is eventually inserted into the table, then SalesCustAccount is there.  I've debugged for days and cannot figure it out yet.

    I'm going to keep plugging away at it and find a solution.  I do appreciate all the suggestions, but I have a feeling this is a unique scenario that can't be solved with standard methods.

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: Code stopped working after update

    Do one thing - Just open the table AMDeviceTable - Navigate to fields right click "SalesCustAccount" >> Find references - This will show all the objects that are using this fields. From there you can find out the classes or forms that are using this fields.

    Thanks,

    Girish S.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,841

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 783 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 490 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans