Share via


CreateVendor

Description

This method creates a new vendor.

Parameters

Parameter

Type

Description

vendor

Vendor

The vendor object being created.

context

Context

Specifies information about how the method will be called.

policy

Policy

Specifies the set of behaviors and behavior options to be applied during the operation.

Interfaces

  • Dynamics GP
  • Purchasing

Examples

The following C# example creates a vendor with the key value "NewVendor001". The Name property is set, and all other properties are left as default values.

Cc508545.LegacyEndpoint(en-us,MSDN.10).gif** Legacy endpoint**

using System;
using System.Collections.Generic;
using System.Text;
using DynamicsGPWebServiceSample.DynamicsGPService;

namespace DynamicsGPWebServiceSample
{
    class Program
    {
        static void Main(string[] args)
        {
            CompanyKey companyKey;
            Context context;
            Vendor vendor;
            VendorKey vendorKey;
            Policy vendorPolicy;

            // Create an instance of the service
            DynamicsGP wsDynamicsGP = new DynamicsGP();

            // Be sure the default credential are being used
            wsDynamicsGP.UseDefaultCredentials = true;

            // Create a context object with which to call the service
            context = new Context();

            // Specify which comany to use (sample company)
            companyKey = new CompanyKey();
            companyKey.Id = (-1);

            // Set up the context
            context.OrganizationKey = (OrganizationKey)companyKey;

            // Create a new vendor key
            vendorKey = new VendorKey();
            vendorKey.Id = "NewVndr001";

            // Populate the vendor object
            vendor = new Vendor();
            vendor.Key = vendorKey;
            vendor.Name = "New Vendor 001";

            // Get the create policy for vendor
            vendorPolicy = wsDynamicsGP.GetPolicyByOperation("CreateVendor", context);

            // Create the vendor
            wsDynamicsGP.CreateVendor(vendor, context, vendorPolicy);
        }
    }
}

Cc508545.NativeEndpoint(en-us,MSDN.10).gif** Native endpoint **

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;
            Vendor vendor;
            VendorKey vendorKey;
            Policy vendorPolicy;

            // Create an instance of the service
            DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();

            // Be sure the default credential are being used
            // Create a context object with which to call the service
            context = new Context();

            // Specify which comany to use (sample company)
            companyKey = new CompanyKey();
            companyKey.Id = (-1);

            // Set up the context
            context.OrganizationKey = (OrganizationKey)companyKey;

            // Create a new vendor key
            vendorKey = new VendorKey();
            vendorKey.Id = "NewVndr001";

            // Populate the vendor object
            vendor = new Vendor();
            vendor.Key = vendorKey;
            vendor.Name = "New Vendor 001";

            // Get the create policy for vendor
            vendorPolicy = wsDynamicsGP.GetPolicyByOperation("CreateVendor", context);

            // Create the vendor
            wsDynamicsGP.CreateVendor(vendor, context, vendorPolicy);

            // Close the service
            if(wsDynamicsGP.State != CommunicationState.Faulted)
            {
                wsDynamicsGP.Close();
            }
        }
    }
}