Thursday, October 18, 2007

Cómo crear un ajuste de inventario Dynamics GP 9. CreateInventoryAdjustment

Para crear un nuevo ajuste de inventario desde los Web Services for Dynamics GP 9, debemos tener en cuenta primero los campos obligatorios que necesitamos pasarle al objeto, estos son:

Para la cabecera:
Key: número del documento
BatchKey: lote
Date: fecha

Para el detalle:
Key: número de cabecera
ItemKey: id de artícullo
Quantity: Cantidad
WarehouseKey: id de sitio donde se encuentra el item

Existen otras propiedades más pero estas nos ayudarán a crear un ajuste de inventario básico.

Ejemplo:

InventoryAdjustment ivadj = new InventoryAdjustment();

//-----------Lote-------------------------------------------------

BatchKey bk = new BatchKey();

bk.Id = "NombreDeLote";

ivadj.BatchKey = bk;

//-----------NumeroDocumento-------------------------------------------------

InventoryKey ivk = new InventoryKey();

ivk.Id = "00019";

ivadj.Key = ivk;

//-----------Fecha-------------------------------------------------

ivadj.Date = new DateTime(2007,5 ,3);

//-----------Lineas-------------------------------------------------

InventoryAdjustmentLine[] lineas = new InventoryAdjustmentLine[1];

//-----------------Numero cabecera----------------------------

InventoryLineKey ivlk = new InventoryLineKey();

InventoryKey ik = new InventoryKey();

ik.Id = "00019";

ivlk.InventoryKey = ik;

lineas[0].Key = ivlk;

//-----------------Articulo----------------------------

ItemKey itk = new ItemKey();

itk.Id = "100XLG";

lineas[0].ItemKey = itk;

//----------------Sitio----------------------------

WarehouseKey whk = new WarehouseKey();

whk.Id = "WAREHOUSE";

lineas[0].WarehouseKey = whk;

//----------------Cantidad----------------------------

Quantity q = new Quantity();

q.Value = 1;

lineas[0].Quantity = q;

//----------------Llamar al WS para crear en ajuste de inventario----------------------------

Policy pol = wsDynamicsGP.GetPolicyByOperation("CreateInventoryAdjustment", context);

wsDynamicsGP.CreateInventoryAdjustment(ivadj, context, pol);


Si no llenamos estas propiedades que son obligatorias, el web service nos dará un error.
Por ejemplo si no llenamos la propiedad Key nos saldra el siguiente error:

Microsoft.GreatPlains.eConnect Version=9.0.0.0

.Net SqlClient Data Provider

Procedure or Function 'taIVTransactionLineInsert' expects parameter '@I_vIVDOCNBR', which was not supplied.

at Microsoft.GreatPlains.eConnect.eConnectMethods.ExecStoredProcedures(String xml)

...

Por eso es necesario llenar estas propiedades que son obligatorias.

2 comments:

Cesar Gallegos said...

Buena Cosa!!

Excelente!!

ceduardodch said...

Que tal XAP como envio el unitcost para que GP no ponga su CURRENTCOST AYUDA