-->

Save data to different company

2019-01-29 08:10发布

问题:

We've got code to use the Acumatica Web Services inside of an Acumatica BLC, because we want to save data to a different company. I was made aware of another way to do this without using the Web Services - something such as a 'company context' or the like, but I'm not able to find any references to this.

Is there an existing example to create a graph of a screen with a different company context in order to save data to that company?

回答1:

To save data to a different company, you should execute your code within PXLoginScope. In the sample below new Stock Item is saved under the NewCompany tenant:

using (PXLoginScope ls = new PXLoginScope("admin@NewCompany"))
{
    InventoryItemMaint maint = PXGraph.CreateInstance<InventoryItemMaint>();
    InventoryItem item = new InventoryItem();
    item.InventoryCD = "TEST";
    item = maint.Item.Insert(item);
    item.ItemClassID = "ALLOTHER";
    maint.Item.Update(item);
    maint.Actions.PressSave();
}


标签: acumatica