Method InitFrom

Friends, good morning.

I created a column in the table InventTable and would like to retrieve data from another table using the method as InitFrom code below, however, is not working.
Can anyone help me?

My DAX is 2009.

hugs


<i><b>void initFromCustVendExternalItem(CustVendExternalItem table)
{
this.ExternalItemId               = table.ExternalItemId;
}</b></i>

What does “is not working” mean? What code did you write in the first place?

Hi Martin !

I again.

The code has no errors, but the data in the table CustVendExternalItem are not brought to the table InventTable.
I need that if an item is changed in InventTable table, this field I “mirror” will automatically be changed in CustVendExternalItem table also.

Can you show us how you call initFromCustVendExternalItem() and update InventTable? That’s likely the part where the problem lies.

First, I created a field in InventTable table with the same configuration in this field CustVendExternalItem table.
insert InitFrom method in InventTable table.
Then the form InventTable, added the column created.
But the data did not appear.

If you don’t have any code to actualy update InventTable, well, then no such update will ever be done.

As I understand, you want something like this in CustVendExternalItem.update():

if (this.Field1 != this.orig().Field1)
{
    inventTable = InventTable::find(this.ItemId, true);
    inventTable.initFromCustVendExternalItem(this);
    inventTable.update();
}

Martin, thank you for your attention.
See, I created the following method in CustVendExternalIten as you instructed:

public void update ()
{
InventTable inventTable;

if (this.ExternalItemId! this.orig = (). ExternalItemId)
{
inventTable = InventTable :: find (this.ItemId, true);
inventTable.initFromCustVendExternalItem (this);
inventTable.update ();
}

super ();
}

Kept in InventTable, another method:

void initFromCustVendExternalItem (CustVendExternalItem table)
{
this.ExternalItemId = table.ExternalItemId;
}

But still, the data were not mirrored.

First of all, the code you provided (this.ExternalItemId! this.orig = (). ExternalItemId) makes no sense and wouldn’t compile. Either you’re ignoring compilation errors and try to work with something that can’t run at all, or you gave us different code than you actually use. Neither is very helpful.

When you manage to write compilable code, you can’t just stop with “it doesn’t work” - you have to debug the code and isolate the problem. For example:

  • Put a breakpoint to the initFrom method and run your logic. Verify that the right InventTable record is being update with right data.
  • If the method doesn’t get called at all, debug the code that should call it.
  • If it doesn’t contain right data, you have a problem before initFrom. Depending on whether the problem is with InventTable or CustVendExternalItem, debug the appropriate part of code.
  • If everything correctly updates in initFrom but the record but it doesn’t get saved to database, the problem is in saving - maybe update() isn’t called, something skips super() in update(), the transaction is aborted or so. Walk through code in debugger to see where it fails.

We obviously can’t debug the code for you, because we don’t have it. (And the problem isn’t important enough for you to debug it, why should it be more important for us?)

Martin,

grateful for the assistance given. Here we have many problems with our partners that should pass in training for development, but even they know for sure and unfortunately I need to use the forums to try to make our work more practical. The little that we develop here is the expense of self-learning and people like you willing to help us.

I’m trying to accomplish what you said, if successful warning again.

hugs.