Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Change QuantityType via web services through CreateInventoryTransfer

(0) ShareShare
ReportReport
Posted on by 50

I am trying to change the QuantityType of an item for damaged goods through web services via the CreateInventoryTransfer method. I am basically transferring the inventory from and to the same warehouse, but I am increasing/decreasing the On Hand quantity and moving it to or taking it away from the Damaged quantity.

I'm having a little trouble with the syntax of creating and assigning the values to quantityTypeFromField and quantityTypeToField in my code. This is what I have so far.

<code>

       public string FromQuantityType

       {

           get

           {

               return sFromQuantityType;

           }

           set

           {

               sFromQuantityType = value;

           }

       }

       public void Post()

       {

           Quantity itemQuantity;

           QuantityType fromQuantityType;

           QuantityType toQuantityType;

           // Create a quantity object to specify the amount of the transfer

           itemQuantity = new Quantity();

           itemQuantity.Value = this.ItemQuantity;

           // Create a quantity type object to specify the original type of quantity

           fromQuantityType = new QuantityType();

<\code>

When I try to assign the value to fromQuantityType, this.FromQuantityType isn't working and there is no ToString() or anything like that to help convert the value. The error I get is "Cannot implicitly convert type 'string' to 'GPI.WMS.DynamicsGPWebservice.QuantityType'. I can post more of my code upon request, but I'm hoping I'm missing something obvious and someone can point it out to me.

Thanks in advance!

*This post is locked for comments

  • bherring1979 Profile Picture
    bherring1979 50 on at
    RE: Change QuantityType via web services through CreateInventoryTransfer

    The example code provided doesn't address the QuantityType issue which is what I am trying to work through. I have seen this example code on the MSDN site. It helped me get to the point that I'm at now, but I am not able to find anything specifically related to the issue I'm having.

  • soma Profile Picture
    soma 24,410 on at
    RE: Change QuantityType via web services through CreateInventoryTransfer

    Try the below sample code instead of your above code for inventory transfer.

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.ServiceModel;

    using DynamicsGPWebServiceSample.DynamicsGPService;

    namespace DynamicsGPWebServiceSample

    {

       class Program

       {

           static void Main(string[] args)

           {

               CompanyKey companyKey;

               Context context;

               BatchKey batchKey;

               ItemKey itemKey;

               Quantity itemQuantity;

               WarehouseKey fromWarehouseKey;

               WarehouseKey toWarehouseKey;

               InventoryKey inventoryKey;

               InventoryLineKey inventoryLineKey;

               InventoryTransfer inventoryTransfer;

               InventoryTransferLine inventoryTransferLine;

               Policy inventoryTransferCreatePolicy;

               // Create an instance of the service

               DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();

               // Create a context with which to call the service

               context = new Context();

               // Specify which company to use (sample company)

               companyKey = new CompanyKey();

               companyKey.Id = (-1);

               // Set up the context object

               context.OrganizationKey = (OrganizationKey)companyKey;

               // Create an inventory key to identify the inventory transfer object

               inventoryKey = new InventoryKey();

               inventoryKey.Id = "WSINVTRFR00000010";

               // Create a batch key object to specify a batch for the inventory transfer

               batchKey = new BatchKey();

               batchKey.Id = "TRANSFER 1";

               // Create an inventory transfer object

               inventoryTransfer = new InventoryTransfer();

               // Populate the inventory transfer object's required properties

               inventoryTransfer.Key = inventoryKey;

               inventoryTransfer.BatchKey = batchKey;

               inventoryTransfer.Date = DateTime.Today;

               // Create an inventory transfer line object to detail the inventory transfer

               inventoryTransferLine = new InventoryTransferLine();

               // Create an inventory line key to identify the inventory transfer line object

               inventoryLineKey = new InventoryLineKey();

               inventoryLineKey.InventoryKey = inventoryKey;

               // Create an item key object to specify the item

               itemKey = new ItemKey();

               itemKey.Id = "128 SDRAM";

               // Create a quantity object to specify the amount of the transfer

               itemQuantity = new Quantity();

               itemQuantity.Value = 5m;

               // Create a warehouse key to specify the location originating the transfer

               fromWarehouseKey = new WarehouseKey();

               fromWarehouseKey.Id = "WAREHOUSE";

               // Create a warehouse key to specify the location receiving the transfer

               toWarehouseKey = new WarehouseKey();

               toWarehouseKey.Id = "WAREHOUSE";

               // Populate the required properties of the inventory transfer line object

               inventoryTransferLine.Key = inventoryLineKey;

               inventoryTransferLine.ItemKey = itemKey;

               inventoryTransferLine.Quantity = itemQuantity;

               inventoryTransferLine.WarehouseFromKey = fromWarehouseKey;

               inventoryTransferLine.WarehouseToKey = toWarehouseKey;

               // Create an array to hold the inventory transfer line object

               InventoryTransferLine[] lines = { inventoryTransferLine };

               // Add the array of inventory transfer lines to the inventory transfer object

               inventoryTransfer.Lines = lines;

               // Get the create policy for an inventory transfer

               inventoryTransferCreatePolicy = wsDynamicsGP.GetPolicyByOperation(

               "CreateInventoryTransfer", context);

               // Create the inventory transfer

               wsDynamicsGP.CreateInventoryTransfer(inventoryTransfer,

               context, inventoryTransferCreatePolicy);

               // Close the service

               if(wsDynamicsGP.State != CommunicationState.Faulted)

               {

                   wsDynamicsGP.Close();

               }

           }

       }

    }

    Note: I don't have web services on my environment. So, couldn't provide the exact code. Try  the above sample code. Replace the hard coded values with your input values and additionally create the quantity type object to pass the fromQtyType and toQtyType.

    Hope this helps!!!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans