Skip to Content

Duplicate Stock Transfer - DI API

Good day experts,

I am developing an application that converts stock transfer requests to stock transfers, only I came across one detail: at the moment of making that conversion and generating the stock transfer, the inventory is already affected , but I require a way to duplicate that last move to only edit the source and destination warehouse, and create an exact copy but with different warehouse, without requiring to redefine all lines from the beginning, this to automate a warehouse process.

I searched the forum and the web, but I do not find any way to achieve this, could someone confirm me if it's possible? If yes, could you provide me with an example or resource that can consult to get it?

Thank you in advance for your support, best regards!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Sep 05, 2017 at 02:27 PM

    Hi Luis,

    A full sample:

    StockTransfer oStTransfer = null;
    try
    {
        //Set up your company object to work with xml import/export.
        oCompany.XmlExportType = BoXmlExportTypes.xet_ExportImportMode;
        oCompany.XMLAsString = true;
        string xmlStockTransfer = string.Empty;
    
    
        //Load your last stock transfer.
        oStTransfer = oCompany.GetBusinessObject(BoObjectTypes.oStockTransfer);
        if (oStTransfer.GetByKey(9980))
        {
            //Convert your strock transfer object in a xml
            xmlStockTransfer = oStTransfer.GetAsXML();
        }
    
    
        if (!string.IsNullOrEmpty(xmlStockTransfer))
        {
            //Intialize a new stock transfer through your xml
            oStTransfer = oCompany.GetBusinessObjectFromXML(xmlStockTransfer, 0);
            //Change the fields that you want.
            for (int i = 0; i < oStTransfer.Lines.Count; i++)
            {
                oStTransfer.Lines.SetCurrentLine(i);
                oStTransfer.Lines.FromWarehouseCode = "014.01";
                oStTransfer.Lines.WarehouseCode = "001.01";
            }
            //Add the new transfer.
            if (oStTransfer.Add() != 0)
            {
                MessageBox.Show(oCompany.GetLastErrorDescription());
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    

    Hope it helps.

    Kind Regards,

    Diego Lother

    Add comment
    10|10000 characters needed characters exceeded