ax 2009 integration through businessconnector

Hi Everyone,

i am integrating ax 2009 to other application,so i wrote some code in visual C# and project type template is asp.net web service application,

i wrote code of insert type of methods in this project , i have taken some fields in “BankAccountTable” ,that fields inserted in successfully in ax 2009 table BankAccountTable through service what i am inserted,

but i again taken one field "bankcodetype " from table,but it is enum value in AX, how to declare in c# code.

can anyone help on this problem

thanks regards

Hi Naveen,

Plz refer the below code, i hope this will help you. for this I user PurchaseType as enum.

The enum contains Journal, Purchase Order, Return Order as enum values, so i directly passing the Journal to the Enum.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Services;

using Microsoft.Dynamics.BusinessConnectorNet;

namespace WebApplication1

{

///

/// Summary description for WebService1

///

[WebService(Namespace = “http://tempuri.org/”)]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.ComponentModel.ToolboxItem(false)]

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

// [System.Web.Script.Services.ScriptService]

public class WebService1 : System.Web.Services.WebService

{

Axapta ax;

AxaptaRecord axRecord;

String tableName = “Table3”;

[WebMethod]

public string HelloWorld()

{

ax = new Axapta();

ax.Logon(“USMF”, “en-us”, “”, “”);

using (axRecord = ax.CreateAxaptaRecord(tableName))

{

axRecord.set_Field(“PurchaseType”, “Journal”);

axRecord.Insert();

}

return “Hello World”;

}

}

}

Hi Raman,

i tried but it will be not working,i wrote code below like:\

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Services;

using Microsoft.Dynamics.BusinessConnectorNet;

namespace SampleInventory

{

///

/// Summary description for Service1

///

[WebService(Namespace = “http://tempuri.org/”)]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.ComponentModel.ToolboxItem(false)]

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

// [System.Web.Script.Services.ScriptService]

public class Service1 : System.Web.Services.WebService

{

Axapta ax;

[WebMethod]

public string CrateInventory(String accountID, String name, String bankGroupId, String currencyCode, String registrationNum, String ledgerAccount, String accountNum, String sWIFTNo,

String companyPaymId, String iBAN, String address, String street, String zipCode, String city, String county, String state, String countryRegionId)

{

try

{

ax = new Axapta();

ax.Logon(“CEU”, “en-us”, “”, “”);

AxaptaRecord axRecord;

String tableName = “BankAccountTable”;

using (axRecord = ax.CreateAxaptaRecord(tableName))

{

axRecord.InitValue();

axRecord.set_Field(“AccountID”, accountID);

axRecord.set_Field(“Name”, name);

axRecord.set_Field(“BankGroupId”, bankGroupId);

axRecord.set_Field(“CurrencyCode”, currencyCode);

axRecord.set_Field(“RegistrationNum”, registrationNum);

axRecord.set_Field(“LedgerAccount”, ledgerAccount);

axRecord.set_Field(“AccountNum”, accountNum);

axRecord.set_Field(“SWIFTNo”, sWIFTNo);

axRecord.set_Field(“CompanyPaymId”, companyPaymId);

axRecord.set_Field(“IBAN”, iBAN);

axRecord.set_Field(“Address”, address);

axRecord.set_Field(“Street”, street);

axRecord.set_Field(“ZipCode”, zipCode);

axRecord.set_Field(“City”, city);

axRecord.set_Field(“County”, county);

axRecord.set_Field(“State”, state);

axRecord.set_Field(“CountryRegionId”, countryRegionId);

axRecord.set_Field(“BankCodeType”,“BL”); // this one is enumtype

//axRecord.set_Field(“BankCodeType”, bankCodeType);

axRecord.Insert();

}

}

catch (Exception e)

{

Console.WriteLine(“Error encountered :{0}”, e.Message);

}

return “Created”;

}

}

}

when i started debug,goto the service,i entered all values,after that ,i checked in ax 2009 bankaccounttable,but the record not inserted,
when i remove the enum field it will be displayed the record

Enums are just named integer number, therefore you can use the value (e.g. 3) directly.

You’ll make it easier for yourself if you create a new .NET enum with exactly the same values as the enum in AX. You can even generate it from AX by something like this:

EnumId enumId = enumNum(BankCodeType);
SysDictEnum de = new SysDictEnum(enumId);
int value = de.firstValue();
int lastValue = de.lastValue();
str output;
str prefix;
int i;
#File

output = strFmt('public enum %1', de.name());
output += #delimiterCRLF + '{';

for (i=0; i<de.values(); i++)
{
    if (i == 0)
    {
        prefix = #delimiterCRLF + '    ';
    }
    else
    {
        prefix = ',' + #delimiterCRLF + '    ';
    }

    output += strFmt("%1%2 = %3", prefix, de.index2Symbol(i), de.index2Value(i));
}
output += #delimiterCRLF + '}';
info(output);