eConnect – Inventory – Item create – example – VB.net – C#

Inventory

VB

Imports System
Imports System.Xml
Imports System.Xml.Serialization
Imports System.IO
Imports System.Text
Imports Microsoft.VisualBasic
Imports Microsoft.Dynamics.GP.eConnect
Imports Microsoft.Dynamics.GP.eConnect.Serialization

Public Class Inventory
    Public Sub eConnectSend()
        'Serialized XML File         
        Dim xmldocument As String
        'Connection String         
        Dim sConnectionString As String
        'Result         
        Dim xmlobject As String
        Using eConCall As New eConnectMethods
            Try
                SerializeObject("c:\test\xmlfile.xml ")
                Dim xmldoc As New Xml.XmlDocument
                xmldoc.Load("c:\test\xmlfile.xml")
                xmldocument = xmldoc.OuterXml
                sConnectionString = "data source=sqlserver;initial catalog=two;integrated security=SSPI; persist security info=False;packet size=4096"
                xmlobject = eConCall.CreateTransactionEntity(sConnectionString, xmldocument)
            Catch exp As eConnectException
                MsgBox(exp.ToString)
            Catch ex As System.Exception
                MsgBox(ex.ToString)
            Finally
                eConCall.Dispose()
                MsgBox("done")
            End Try
        End Using
    End Sub
    Public Shared Sub SerializeObject(ByVal filename As String)
        Try
            Dim econnect As New eConnectType
            Dim iv As New IVItemMasterType

            'inventory item
            Dim itm As New taUpdateCreateItemRcd
            With itm
                .ITEMNMBR = "ITEMNAME"
                .ITEMDESC = "Item description"
                .ITMSHNAM = "Short Description"
                .ITMGEDSC = "Generic description"
                .ITMCLSCD = "FG-ACT"
                .ITEMTYPE = 1
                .UOMSCHDL = "EACH"
                .UpdateIfExists = 1
            End With
            iv.taUpdateCreateItemRcd = itm

            ReDim Preserve econnect.IVItemMasterType(0)
            econnect.IVItemMasterType(0) = iv

            Dim fs As New FileStream(filename, FileMode.Create)
            Dim writer As New XmlTextWriter(fs, New UTF8Encoding)
            Dim serializer As New XmlSerializer(GetType(eConnectType))
            serializer.Serialize(writer, econnect)
            writer.Close()
        Catch ex As ApplicationException
            MsgBox(ex.ToString)
        End Try
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        eConnectSend()
    End Sub
End Class

C#

using System;
using System.IO;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.Dynamics.GP.eConnect;
using Microsoft.Dynamics.GP.eConnect.Serialization;

namespace eConnectSample
{
    public partial class InventoryItemCreate : Form
    {
        public InventoryItemCreate()
        {
            InitializeComponent();
        }

        private static void sendtogp()
        {
            using (eConnectMethods eConCall = new eConnectMethods())
            {
                try
                {
                    SerializeObject("c:\\test\\eConnect.xml");
                    XmlDocument xmldoc = new XmlDocument();
                    xmldoc.Load("c:\\test\\eConnect.xml");
                    string send2gp = xmldoc.OuterXml;
                    string sConnectionString = "data source=sqlserver;initial catalog=TWO;integrated security=SSPI;persist security info=False;packet size=4096";
                    string ivitem = eConCall.CreateTransactionEntity(sConnectionString, send2gp);
                }
                catch (eConnectException exp)
                {
                    MessageBox.Show(exp.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    eConCall.Dispose();
                    MessageBox.Show("done");
                }
            }
        }

        private static void SerializeObject(string filename)
        {

            try
            {
                taUpdateCreateItemRcd itm = new taUpdateCreateItemRcd();
                itm.ITEMNMBR = "ITEMNAME";
                itm.ITEMDESC = "Item description";
                itm.ITMSHNAM = "Short Description";
                itm.ITMGEDSC = "Generic description";
                itm.ITMCLSCD = "FG-ACT";
                itm.ITEMTYPE = 1;
                itm.UOMSCHDL = "EACH";
                itm.UpdateIfExists = 1;

                IVItemMasterType iv = new IVItemMasterType();
                iv.taUpdateCreateItemRcd = itm;

                IVItemMasterType[] myIV = { iv };
                eConnectType eConnect = new eConnectType();
                eConnect.IVItemMasterType = myIV;

                FileStream fs = new FileStream(filename, FileMode.Create);
                XmlTextWriter writer = new XmlTextWriter(fs, new UTF8Encoding());

                XmlSerializer serializer = new XmlSerializer(eConnect.GetType());
                serializer.Serialize(writer, eConnect);
                writer.Close();
            }

            catch (eConnectException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void Send2GP_Click(object sender, EventArgs e)
        {
            sendtogp();
        }
    }
}

Adapted from Microsoft Dynamics GP eConnect Samples installed during eConnect installation.

Line breaks are issued to fit script within screen. Remove line breaks.

THIS CODE AND INFORMATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

XML File

<?xml version="1.0" ?>
<eConnect xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <IVItemMasterType>
    <eConnectProcessInfo xsi:nil="true"/>
    <taRequesterTrxDisabler_Items xsi:nil="true"/>
    <taUpdateCreateItemRcd>
      <ITEMNMBR>
        ITEMNAME
      </ITEMNMBR>
      <ITEMDESC>
        Item description
      </ITEMDESC>
      <ITMSHNAM>
        Short Description
      </ITMSHNAM>
      <ITMGEDSC>
        Generic description
      </ITMGEDSC>
      <ITMCLSCD>
        FG-ACT
      </ITMCLSCD>
      <UOMSCHDL>
        EACH
      </UOMSCHDL>
    </taUpdateCreateItemRcd>
    <taUpdateCreateItemCurrencyRcd_Items xsi:nil="true"/>
    <taIVCreateItemPriceListLine_Items xsi:nil="true"/>
    <taIVCreateItemPriceListHeader xsi:nil="true"/>
    <taItemSite_Items xsi:nil="true"/>
    <taCreateItemVendors_Items xsi:nil="true"/>
    <taCreateKitItemRcd_Items xsi:nil="true"/>
    <taCreateInternetAddresses_Items xsi:nil="true"/>
  </IVItemMasterType>
</eConnect>

 

 

Extract from eConnect Programmers Reference Guide for immediate reference.

<taUpdateCreateItemRcd>
Element name Data type Length Required Description
ITEMNMBR string 30 Y Item number
ITEMDESC string 100 N Item description
ITMSHNAM string 15 N Short description
ITMGEDSC string 10 N Generic description
ITMCLSCD string 10 N Class ID
ITEMTYPE i4 2 N Item type
1=Sales inventory;
2=Discontinued;
3=Kit;
4=Miscellaneous charges;
5=Services;
6=Flat fee
Default is one on new record
VCTNMTHD i4 2 N Valuation method:
0=Any ITEMTYPE other than 1 or 2;
1=FIFO perpetual;
2=LIFO perpetual;
3=Average perpetual;
4=FIFO periodic;
5=LIFO periodic
Default is one on new record
TAXOPTNS i4 2 N Sales tax options:
1=Taxable;
2=Nontaxable;
3=Base on customers
Default is one on new record
ITMTSHID string 15 N Tax schedule ID
UOMSCHDL string 10 N Unit of measure schedule ID
Required for a new record, but can roll down from class
ITEMSHWT number N Shipping weight; only used when ITEMTYPE=1, 2, or 3
TCC string 30 N Tax community code; only used if the “Enable Intrastat Tracking” option is enabled in Company Setup
CNTRYORGN string 6 N Country origin; only used if the “Enable Intrastat Tracking” option is enabled in Company Setup
DECPLQTY i4 2 N Quantity Decimals; DECPLQTY can equal 0, 1, 2, 3, 4, or 5; if ITEMTYPE=3, then DECPLQTY must be set to zero
Default is zero on new record
DECPLCUR i4 2 N Currency Decimals; used for item if not registered for multi-currency or used for functional currency
If registered for multi-currency and want other currencies, use the <taUpdateCreateItemCurrencyRcd> node.
Purchase_Tax_Options i4 2 N Purchasing tax option:
1=Taxable;
2=Nontaxable;
3=Base on vendors
Default is one on new record
Purchase_Item_Tax_Schedu string 15 N Purchase tax schedule ID
STNDCOST number 21 N Standard cost
CURRCOST number 21 N Current cost
LISTPRCE number 21 N List price; used if multi-currency is not registered or used for functional currency if multi-currency is registered
NOTETEXT string 8000 N Note text
ALTITEM1 string 30 N Alternate item 1
ALTITEM2 string 30 N Alternate item 2
ITMTRKOP i4 2 N Item tracking:
1=None;
2=Serial Numbers;
3=Lot Numbers
Used when ITEMTYPE= 1 or 2
Default is one on new record
LOTTYPE string 10 N Lot category
LOTEXPWARN i4 1 N Lot Expiration Warn:
0 = no warning
1 = warnings enabled
If this item is not lot tracked, the value of this element is not used.
LOTEXPWARNDAYS i4 2 N Days Before Lot Expires:
Valid entries equal 0 – 999.
If LOTEXPWARN is 0 then LOTEXPWARNDAYS always defaults to 0. If this item is not lot tracked, the value of this element is not used.
INCLUDEINDP i4 1 N Include in Demand Planning;
0=Do Not Include;
1=Include
Default is zero on new record
MINSHELF1 i4 2 N Minimum shelf life 1:
Valid entries equal 0-9999
Use when ITMTRKOP=3
Default is zero on new record
MINSHELF2 i4 2 N Minimum shelf life 2:
Valid entries equal 0-9999
Use when ITMTRKOP=3
Default is zero on new record
ALWBKORD i4 1 N Allow back orders:
0=Do not allow back orders;
1=Allow back orders
Default is zero on new record
WRNTYDYS i4 2 N Warranty days; valid entries equal 0-9999
Default is zero on new record
ABCCODE i4 2 N ABC code:
1=None;
2=A;
3=B;
4=C
Default is one on new record
USCATVLS_1 string 10 N User category 1
USCATVLS_2 string 10 N User category 2
USCATVLS_3 string 10 N User category 3
USCATVLS_4 string 10 N User category 4
USCATVLS_5 string 10 N User category 5
USCATVLS_6 string 10 N User category 6
KPCALHST i4 1 N Maintain history—calendar year:
0=Do not keep history;
1=Keep history
Default is 0 on new record
KPERHIST i4 1 N Maintain history—fiscal year:
0=Do not keep history;
1=Keep history
Default is 0 on new record
KPTRXHST i4 1 N Maintain history—transaction:
0=Do not keep history;
1=Keep history
Default is 0 on new record
KPDSTHST i4 1 N Maintain history—distribution:
0=Do not keep history;
1=Keep history
Default is 0 on new record
IVIVACTNUMST string 75 N Inventory account
IVIVOFACTNUMST string 75 N Inventory offset account
IVCOGSACTNUMST string 75 N Cost of goods sold account
IVSLSACTNUMST string 75 N Sales account
IVSLDSACTNUMST string 75 N Markdown account
IVSLRNACTNUMST string 75 N Sales return account
IVINUSACTNUMST string 75 N In use account
IVINSVACTNUMST string 75 N In service account
IVDMGACTNUMST string 75 N Damaged account
IVVARACTNUMST string 75 N Variance account
DPSHPACTNUMST string 75 N Drop-ship items account
PURPVACTNUMST string 75 N Purchase price variance account
UPPVACTNUMST string 75 N Unrealized purchase price variance account
IVRETACTNUMST string 75 N Inventory returns account
ASMVRACTNUMST string 75 N Assembly variance account
KTACCTSR i4 2 N Cost of goods sold account source:
0=From component item;
1=From kit item
Default is zero on new record
PRCHSUOM string 8 N Purchasing unit of measure
Revalue_Inventory i4 1 N Revalue inventory for cost variance:
0=Do not revalue;
1=Revalue
Default is zero on new record
Tolerance_Percentage number 21 N Tolerance percentage
LOCNCODE string 10 N Location code; assigns site to item if it is not already assigned
PRICMTHD i4 2 N Price method:
1=Currency amount;
2=Percent of List price;
3=Percent of markup of current cost;
5=Percent margin of current cost;
6=Percent margin of standard cost
Default is one
PriceGroup string 10 N Price group
UseQtyOverageTolerance i4 1 N Use quantity overage tolerance:
0=Do not use;
1=Use
UseQtyShortageTolerance i4 1 N Use quantity shortage tolerance:
0=Do not use;
1=Use
QtyOverTolerancePercent i4 4 N Quantity over tolerance percent:
Provide a value of 0 – 99999. For example, 99999 equals 99.999.
QtyShortTolerancePercent i4 4 N Quantity short tolerance percent:
Provide a value of 0 – 99999. For example, 99999 equals 99.999.
UseItemClass i4 1 N Flag to have class setting roll down to elements that are not passed in; uses the ITMCLSCD class
UpdateIfExists i4 1 N Flag to allow item data to be updated if it exists: 0=Do not update;
1=Update if exists;
2=Create if record does not exist and exits without error if record does exist
RequesterTrx i4 2 N Requester transaction
0=False;
1=True (if True, it populates the requester shadow table)

Cheers!
Sanjay