Try our conversational search powered by Generative AI!

Create return order programmatically



Is it possible to create and add a return order to a PurchaseOrder programmatically?

I was thinking about Doing it manually, something like:

var returnOrderForm = purchaseOrder.OrderForms.first().Clone() as OrderForm;
returnOrderForm.ReturnType = "Refund";
returnOrderForm.RMANumber = "MyRMANum";

But is this a bad idea?

We run EPiServer 7.5

Henrik Rasmussen

Sep 03, 2015 15:53


It depends on what you want, but we usually do this:

			 OrderForm returnForm = purchaseOrder.ReturnOrderForms.AddNew();
 returnForm.Name = OrderForm.ReturnName;
 returnForm.OrigOrderFormId = purchaseOrder.OrderForms[0].OrderFormId;
 returnForm.ReturnType = ReturnType.Refund;
 returnForm.Status = ReturnFormStatus.AwaitingStockReturn.ToString();
 returnForm.RMANumber = returnForm.ReturnFormNumberMethod(returnForm);
 returnForm.CreatorId = PrincipalInfo.CurrentPrincipal.GetContactId().ToString();
 return returnForm;
So you can ensure some information is more correct this way.

Edited, Sep 04, 2015 13:38

I tried what your suggested but also added a LineItem to the return order. Futrhermore, I called the AcceptChanges() on the returnOrder to acctually save the order in the database. This created a return order, but it seemed corrupted as i tried to edit it from the Commerce Manager it produced an exception. This error revealed that there is a ReturnExchangeManager available in the SDK which implements the procedure Mr Mai suggested which is more comfortable to me.

This is how I used the ReturnExchangeManager:

private void createRefundForm(PurchaseOrder Order, int index, int returnQuantity, String returnReason)
    OrderForm returnForm = ReturnExchangeManager.AddNewReturnFormToPurchaseOrder(Order);
        returnForm, Order.OrderForms[0].LineItems[index], returnQuantity, returnReason);

Where Order is the order to return and the index is the index of the lineitems to return


Sep 09, 2015 9:44
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.