CopyEntity is a method, that is available within any entity. In the model of the AI-Framework, the call is: .Copy. This is the functional name. It copies all fields of an entity (which is a record in memory) to a new entity.
Read more about this in How to > Basic concepts > Entities
public IMethodCall MakeCopyOfOrder()
{
return Method(() =>
{
var currentOrder = OrdersView.CreateItemReference();
var newOrder = OrdersView.CreateItemReference();
return new Body
{
currentOrder.Assign(OrdersView.Current),
newOrder.Assign(currentOrder.Copy()),
newOrder.AssignNextOrderNr(),
newOrder.OrderDateTime.Assign(DateTimeExpression.Now),
newOrder.Status.Assign(OrderStatus.Open),
Orders.Save()
};
})
.SetWorkDescription("make a copy of an order")
.SetImage(CommonImages.ArrowRight)
.Call();
}
This is a method, named MakeCopyOfOrder(), which is situated inside the Entity OrderEntity. It has therefore direct access to the data, related to the table Order.
OrdersView is a view, based on the OrderEntity. The variable currentOrder is defined as a new instance of a record (in memory).newOrder, is also defined as a new instance of a record (in memory).OrdersView to the variable currentRecord.currentOrder, is now copied to the variable newOrder – that is: the new record in memory.Orders.Save().
Anywhere in the model code, where the OrderEntity is available, a button can be placed on a form, that invokes this method: Orders.MakeCopyOfOrder(). If, for example, the form shows a list of orders, clicking the button will make a copy of the order that is currently selected in that list.
Article ID: 359
Created: Tue, Jan 28, 2020
Last Updated: Tue, Jan 28, 2020
Online URL: https://wiki-ai-framework.abstract-it.nl/article/copyentity-359.html