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 :
Microsoft Dynamics AX (Archived)

Update a table in Dynamics AX 2012 automatically based on third field value

(0) ShareShare
ReportReport
Posted on by 1,260

Hi,

I have a field "FieldABC" which is present in two different table "Table1" and "Table2".

I have created a new field "Field2" in table "Table2".

I want to copy the values of field "Field1" from "Table1".

Condition: I run a process and automatically a row is inserted in "Table2", but the field "Field2" is empty. It does not pick up the value automatically from the table "Table1" of field "Field1".

I have tried to use the insert method or update method, but still no output.

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: Update a table in Dynamics AX 2012 automatically based on third field value

    Please use the debugger to see why your code doesn't work as you think it should. If you can't figure out what's wrong, show us your code together with information from debugger, such as where it went wrong, what values were in variables in the moment and so on.

  • Community Member Profile Picture
    on at
    RE: Update a table in Dynamics AX 2012 automatically based on third field value

    Can you please share your code ?

  • Daljit Kaur Rahsi Profile Picture
    1,260 on at
    RE: Update a table in Dynamics AX 2012 automatically based on third field value

    It is similar to this one:

    public void FieldUpdate()

    {

           Table1 table1;

           Table2 table2;

           select forUpdate table1

           where table2.field2=='7854';

           ttsBegin;

           table1.field1='7621454764265';

           table1.Update();

           ttsCommit;

    }

    This method I am using right now when I run the fields are filled up. But I want a method to run automatically whenever a new row is inserted in table1.

    Also, before this I have tried with insert_recordset, insert(), update(), but none worked.

    The method FieldUpdate() works only from the development workspace and not from workspace.

  • Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: Update a table in Dynamics AX 2012 automatically based on third field value

    There are quite a few bugs.

    Above all, the whole select is invalid - you're trying to select table1, but your condition is written against table2, which isn't included in the query at all.

    How did you debug your code? You should immediately see that it doesn't work!

    Let's ignore bugs in your update(), because your requirement doesn't include updates. You want it "to run automatically whenever a new row is inserted", which should be done in insert() method before super() and you don't need any update() there.

    I thought you wanted to copy the value of Table1.Field1, but your code doesn't even try to do anything like that...

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Update a table in Dynamics AX 2012 automatically based on third field value

    Hi daljith

    Do you any relation between table1 and table2

    for example table1.field3 = table2.fieldx.

    if you any relation then use select statement like this

    select forUpdate table1

          where table1.field3 == table2.fieldx

          &&     table2.field2=='7854';   then you will get table1 record.

    then you can do this

          ttsBegin;

          table1.field1='7621454764265';

          table1.Update();

          ttsCommit;

  • Daljit Kaur Rahsi Profile Picture
    1,260 on at
    RE: Update a table in Dynamics AX 2012 automatically based on third field value

    Hi Raghuk35,

    They have ItemID in copy. And thank you for the answer; I did similar to your suggested answer. Thanks again.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans