on 08-15-2017 4:38 PM
Buen día expertos,
Estoy probando un código para crear transferencias de stock en SAP B1, con eso no tengo problema.
Quería consultar si hay algún código o función que pueda convertir o pasar una Solicitud de Traslado a una Transferencia de Stock.
He estado buscando por los foros pero no encuentro nada relacionado con esta conversión.
Espero puedan ayudarme, gracias de antemano!
Hola Luis,
Un código de ejemplo. En este código, realizamos la acción de copia de la solicitud de transferencia de inventario a una transferencia de inventario.
StockTransfer oTransferReq = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryTransferRequest);
if (oTransferReq.GetByKey(1)) //Load a transfer request
{
//initialize a stock transfer
StockTransfer oStTransfer = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer);
oStTransfer.DocDate = DateTime.Now;
//Read lines from Transfer Request
for(int i = 0; i < oTransferReq.Lines.Count; i++)
{
oTransferReq.Lines.SetCurrentLine(i);
if (oStTransfer.Lines.BaseEntry != 0)
oStTransfer.Lines.Add();
//Set the reference for the transfer request, sap will copy the other infos automatically.
oStTransfer.Lines.BaseEntry = oTransferReq.DocEntry;
oStTransfer.Lines.BaseLine = oTransferReq.Lines.LineNum;
oStTransfer.Lines.BaseType = InvBaseDocTypeEnum.InventoryTransferRequest;
}
if (oStTransfer.Add() != 0)
MessageBox.Show(oCompany.GetLastErrorDescription());
}
Espero que ayude.
Atte,
Diego Lother
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hola que tal Diego, primero que nada muchas gracias por tu respuesta.
Estoy tratando de utilizar el código que me proporcionas, pero me marca el error en la siguiente línea:
SAPbobsCOM.StockTransfer oTransferReq = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryTransferRequest);
El error que me aparece es el siguiente:
Referencia a objeto no establecida como instancia de un objeto.
Intenté quitando SAPbobsCOM y poniéndolo, con new oCompany y sin new, etc, pero no he conseguido que funcione. Sabrás qué estoy haciendo mal? Ya está establecida la conexión con la compañía para cuando llega a esa línea de código, por lo que no se me ocurre nada más..
Gracias de antemano por tu tiempo.
Hola Luis,
Este error se produce porque su objeto de empresa no era instanciar.
Muestra completa
private SAPbobsCOM.Company oCompany = null;
private void transfer()
{
if (oCompany == null || !oCompany.Connected)
this.connect();
try
{
StockTransfer oTransferReq = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryTransferRequest);
if (oTransferReq.GetByKey(1)) //Load a transfer request
{
//initialize a stock transfer
StockTransfer oStTransfer = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer);
oStTransfer.DocDate = DateTime.Now;
//Read lines from Transfer Request
for(int i = 0; i < oTransferReq.Lines.Count; i++)
{
oTransferReq.Lines.SetCurrentLine(i);
if (oStTransfer.Lines.BaseEntry != 0)
oStTransfer.Lines.Add();
//Set the reference for the transfer request, sap will copy the other infos automatically.
oStTransfer.Lines.BaseEntry = oTransferReq.DocEntry;
oStTransfer.Lines.BaseLine = oTransferReq.Lines.LineNum;
oStTransfer.Lines.BaseType = InvBaseDocTypeEnum.InventoryTransferRequest;
}
if (oStTransfer.Add() != 0)
MessageBox.Show(oCompany.GetLastErrorDescription());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void connect()
{
try
{
oCompany = new SAPbobsCOM.Company();
oCompany.Server = "your sap database server";
//oCompany.UseTrusted = true;
oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014;
oCompany.CompanyDB = "your company database";
oCompany.UserName = "manager";
oCompany.Password = "your password";
oCompany.DbUserName = "sa";
oCompany.DbPassword = "your sa password";
oCompany.language = SAPbobsCOM.BoSuppLangs.ln_English;
int intRetCode = oCompany.Connect();
if (intRetCode != 0)
{
MessageBox.Show("Something wrong: " + oCompany.GetLastErrorDescription());
}
}
catch (Exception ex)
{
MessageBox.Show("Something wrong: " + ex.Message);
}
}
Espero que ayude.
Atte,
Diego Lother
Hola que tal Diego, me funcionó excelente tu ejemplo, no sé porqué pero creo que el problema era que no tenía el oCompany dentro de la misma función donde se hace la conversión de documento. No he conseguido sacarlo de ahí, pero seguiré investigando.
Por lo pronto gracias a tu ayuda ya pude hacer la creación de una transferencia.
Te agradezco mucho tu tiempo, eres muy amable. Saludos cordiales!
User | Count |
---|---|
104 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.