Vendor import
You
can now access the service externally by using the WSDL URI.
Set up the vendor service reference in Visual Studio
contactList[1] = new Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView()
Inbound port of the vendor service
To call the service, you need to expose the service on a new
inbound port in Microsoft Dynamics AX.
1. Click System administration >Setup
> Services and Application Integration Framework > Inbound
ports, and then click New.
2. Give the new port a name, such
as Vendor Services.
3. Enter a description.
4. Under Service Contract
Customizations, click Service Operations. The Select service
operations form opens.
5. Select the vendVendTableService
operations, move them to the Selected operations pane, and then
click Close.
6. In the Inbound ports form, click Activate.
CSV:
Name
|
MMS Gen Merchants
|
KnownAs
|
MMS Gen Merchants
|
PhoneticName
|
MMS Gen Merchants
|
OrganizationName
|
MMS Gen Merchants
|
NameAlias
|
MMS Gen Merchants
|
CustGroup
|
IT
|
SalesGroup
|
|
DlvMode
|
|
InvoiceAddressType
|
|
PostalLocationName
|
Primary
|
Postalstreet
|
Marol Maroshi
|
PostalBuildingCompliment
|
|
PostalPOBox
|
|
PostalCity
|
Mumbai
|
PostalState
|
MH
|
PostalZip
|
2219099
|
PostalCountry
|
IND
|
PostalRoles
|
Delivery;Invoice;Business
|
IsPostalPrimary
|
Yes
|
ContactLocationName
|
Primary Phone
|
Locator
|
|
ContactType
|
Phone
|
ContactRoles
|
Business
|
IsContactPrimary
|
yes
|
1. Open Visual Studio, and create
a new project.
2. Add a new service reference by
using the WSDL URI for the vendor service from the Inbound ports form.
3. Add a Using statement for the service reference.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Vendors.VendServiceReference;
using System.IO;
using System.Text.RegularExpressions;
namespace Vendors
{
public partial class Vendor : Form
{
internal static int NameIndex = 0;
internal static int KnownAsIndex = 1;
internal static int PhoneticNameIndex = 2;
internal static int OrganizationNameIndex = 3;
internal static int NameAliasIndex = 4;
internal static int CustGroupIndex = 5;
internal static int SalesGroupIndex = 6;
internal static int DlvModeIndex = 7;
internal static int InvoiceAddressTypeIndex = 8;
internal static int PostalLocationNameIndex = 9;
internal static int PostalstreetIndex = 10;
internal static int PostalBuildingComplimentIndex = 11;
internal static int PostalPOBoxIndex = 12;
internal static int PostalCityIndex = 13;
internal static int PostalStateIndex = 14;
internal static int PostalZipIndex = 15;
internal static int PostalCountryIndex = 16;
internal static int PostalRolesIndex = 17;
internal static int IsPostalPrimaryIndex = 18;
internal static int ContactLocationNameIndex = 19;
internal static int
LocatorIndex = 20;
internal static int ContactTypeIndex = 21;
internal static int ContactRolesIndex = 22;
internal static int IsContactPrimaryIndex = 23;
internal static int VendAccountNum = 24;
internal static int VendCurrency = 25;
internal static int InvoiceAccount = 26;
internal static int UPSzone = 27;
internal static int SalestaxGroup = 28;
internal static int PricesInclSalestax = 29;
internal static int CalculateWithholdingTax = 30;
internal static int Warehouse = 31;
internal static int PurchaseOrderpricesAmount = 32;
internal static int Fax = 33;
internal static int Email = 34;
internal static int TermsofPayment = 35;
internal static int Methodofpayment = 36;
internal static int Mobilephone = 37;
internal static int InternetAddress = 38;
public Vendor()
{
InitializeComponent();
}
public static List<string[]>
ParseCSVFile(string path, Boolean hasHeaders)
{
List<string[]>
CSVRows = new List<string[]>();
int rowNumber = 0;
using (StreamReader
inputFile = new StreamReader(path))
{
string line;
string[] line1;
while ((line = inputFile.ReadLine()) != null)
{
String pattern = ",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))";
Regex r = new
Regex(pattern);
line1 = r.Split(line);
if (hasHeaders != true || rowNumber != 0)
{
CSVRows.Add(line1);
}
rowNumber++;
}
}
return CSVRows;
}
private void
button1_Click(object sender, EventArgs e)
{
//VENDOR MASTER CREATION
VendTableServiceClient vendSvcClient = new
VendTableServiceClient();
List<string[]>
VendData = ParseCSVFile("D:\\Vendors.csv",
true);
foreach (string[]
vendor in VendData)
{
AxdVendTable AxdVendor = new
AxdVendTable();
Vendors.VendServiceReference.AxdEntity_DirPartyTable_DirPartyTable
dirPartyTable = new
Vendors.VendServiceReference.AxdEntity_DirPartyTable_DirPartyTable();
AxdEntity_VendTable VendTable = new
AxdEntity_VendTable();
AxdEntity_VendTable[] vendorList = new
AxdEntity_VendTable[1];
EntityKey[] entityKey;
Vendors.VendServiceReference.AxdEntity_DirPartyTable_DirOrganization org
= new
Vendors.VendServiceReference.AxdEntity_DirPartyTable_DirOrganization()
{
KnownAs = vendor[KnownAsIndex],
PhoneticName = vendor[PhoneticNameIndex],
OrganizationName = new
Vendors.VendServiceReference.AxdEntity_OrganizationName[1],
NameAlias = vendor[NameAliasIndex],
Name = vendor[NameIndex]
};
Vendors.VendServiceReference.AxdEntity_OrganizationName orgName = new Vendors.VendServiceReference.AxdEntity_OrganizationName()
{
Name = vendor[OrganizationNameIndex]
};
//Assign organization name to the base
organization.
org.OrganizationName[0] = orgName;
//Add an address to the org. You can add a
loop and add as many address and types you want to here
Vendors.VendServiceReference.AxdEntity_DirPartyPostalAddressView[]
postalAddView = new
Vendors.VendServiceReference.AxdEntity_DirPartyPostalAddressView[1];
postalAddView[0] = new
Vendors.VendServiceReference.AxdEntity_DirPartyPostalAddressView()
{
LocationName = vendor[PostalLocationNameIndex],
BuildingCompliment = vendor[PostalBuildingComplimentIndex],
City = vendor[PostalCityIndex],
State = vendor[PostalStateIndex],
ZipCode = vendor[PostalZipIndex],
Street = vendor[PostalstreetIndex],
CountryRegionId = vendor[PostalCountryIndex],
Roles = vendor[PostalRolesIndex],
IsPrimary =
(Vendors.VendServiceReference.AxdExtType_LogisticsIsPrimaryAddress)Enum.Parse(typeof(Vendors.VendServiceReference.AxdExtType_LogisticsIsPrimaryAddress),
vendor[IsPostalPrimaryIndex])
};
//Add the party Address to the Organization
org.DirPartyPostalAddressView = postalAddView;
Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView[]
contactList = new
Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView[5];
contactList[0] = new
Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView()
{
LocationName = vendor[ContactLocationNameIndex],
Locator = vendor[LocatorIndex],
IsPrimarySpecified = true,
IsPrimary = (Vendors.VendServiceReference.AxdEnum_NoYes)Enum.Parse(typeof(Vendors.VendServiceReference.AxdEnum_NoYes),
vendor[IsContactPrimaryIndex]),
TypeSpecified = true,
Type =
(Vendors.VendServiceReference.AxdEnum_LogisticsElectronicAddressMethodType)Enum.Parse(typeof(Vendors.VendServiceReference.AxdEnum_LogisticsElectronicAddressMethodType),
vendor[ContactTypeIndex]),
Roles = vendor[ContactRolesIndex]
};
{
LocationName = "Fax",
Locator = vendor[Fax],
TypeSpecified = true,
Type = AxdEnum_LogisticsElectronicAddressMethodType.Fax,
Roles = vendor[ContactRolesIndex]
};
contactList[2] = new
Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView()
{
LocationName = "E-mail",
Locator = vendor[Email],
TypeSpecified = true,
Type = AxdEnum_LogisticsElectronicAddressMethodType.Email,
Roles = vendor[ContactRolesIndex]
};
contactList[3] = new
Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView()
{
LocationName = "Mobile phone",
Locator = vendor[Mobilephone],
TypeSpecified = true,
Type =
AxdEnum_LogisticsElectronicAddressMethodType.Phone,
Roles = vendor[ContactRolesIndex]
};
contactList[4] = new
Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView()
{
LocationName = "Internet address",
Locator = vendor[InternetAddress],
TypeSpecified = true,
Type = AxdEnum_LogisticsElectronicAddressMethodType.URL,
Roles = vendor[ContactRolesIndex]
};
//Add the contacts to the organization
org.DirPartyContactInfoView = contactList;
VendTable.AccountNum = vendor[VendAccountNum];
VendTable.Currency =
vendor[VendCurrency];
VendTable.VendGroup = vendor[CustGroupIndex];
VendTable.DlvMode = vendor[DlvModeIndex];
VendTable.InvoiceAccount = vendor[InvoiceAccount];
VendTable.FreightZone = vendor[UPSzone];
VendTable.TaxGroup = vendor[SalestaxGroup];
VendTable.InclTaxSpecified = true;
VendTable.InclTax = (AxdExtType_InclTax)Enum.Parse(typeof(AxdExtType_InclTax), vendor[PricesInclSalestax]);
VendTable.TaxWithholdCalculateSpecified = true;
VendTable.TaxWithholdCalculate = (AxdExtType_NoYesId)Enum.Parse(typeof(AxdExtType_NoYesId),
vendor[CalculateWithholdingTax]);
VendTable.InventLocation = vendor[Warehouse];
VendTable.PurchAmountPurchaseOrderSpecified = true;
VendTable.PurchAmountPurchaseOrder =
(AxdExtType_PurchAmountPurchaseOrder)Enum.Parse(typeof(AxdExtType_PurchAmountPurchaseOrder), vendor[PurchaseOrderpricesAmount]);
VendTable.PaymTermId = vendor[TermsofPayment];
VendTable.PaymMode = vendor[Methodofpayment];
VendTable.DirPartyTable = new
Vendors.VendServiceReference.AxdEntity_DirPartyTable_DirPartyTable[1];// AxdEntity_DirParty_DirPartyTable[1];
VendTable.DirPartyTable[0] = org;
//Add the specific customer to the list
vendorList[0] = VendTable;
AxdVendor.VendTable = vendorList;
//Set the header fields
AxdVendor.DocPurpose =
Vendors.VendServiceReference.AxdEnum_XMLDocPurpose.Original;
AxdVendor.DocPurposeSpecified = true;
entityKey = vendSvcClient.create(null,
AxdVendor);
}
}
}
}
Hi ragavendar
ReplyDeletein my client system some of the services are not display in port wizard, but AOT display the services example vendvendtable, custtable services
please help me
Hi,
ReplyDeleteI am importing Applicant with addresss using above code But i got an error "Document could not be created. Error details: Cannot create a record in Party postal address view (DirPartyPostalAddressView).
Microsoft Dynamics views are read-only".
Can U please help me....
Thanks
Darshana
Can you please guide me for UPDATE also.
ReplyDeleteThanks