ChangeCompany and table buffers

There is a bug with changeCompany keyword which prevents usage of the same initialized table buffer in different companies. For example, in the following code:

InventItemGroup inventItemGroup;

changeCompany ('A')
{
    inventItemGroup.ItemGroupId = 'IA';
    inventItemGroup.insert();
}

changeCompany ('B')
{
    inventItemGroup = null;
    inventItemGroup.ItemGroupId = 'IB';
    inventItemGroup.insert();
}


Without inventItemGroup = null; line the second insert will throw an error:
Cannot create a record in Item groups (InventItemGroup).
Insert operations are not allowed across companies. Please use changecompany keyword to change the current company before inserting the record.

Because buffer still has dataAreaId value equals to 'A' and neither changeCompany nor insert does the substitution automatically.

So you need to either avoid using the same buffer in different companies or do not forget to reset it via assigning null value.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.