Hello guys,
I'm following a tutorial here. I have made some minor changes and still have the code like this.
public static void JobCreateCustomer (Args _args)
{
CustTable custTable;
NumberSeq numberSeq;
Name name ='Financial Derivative';
DirParty dirParty;
DirPartyPostalAddressView dirPartyPostalAddressView;
DirPartyContactInfoView dirPartyContactInfo;
;
/* Marks the beginning of a transaction.
Necessary to utilize the method numRefCustAccount() */
ttsBegin;
custTable.initValue();
try
{
//CustTable
//numberSeq = NumberSeq::newGetNum(CustParameters::numRefCustAccount());
//custTable.AccountNum = numberSeq.num();
custTable.CustGroup ='030';
custTable.Currency ='NGN';
custTable.PaymTermId ='10AE';
custTable.PaymMode ='CHEQUE-03';
custTable.insert(DirPartyType::Organization, name);
//DirParty
/* Creates a new instance of the DirParty class from an address book entity
that is represented by the custTable parameter. */
dirParty = DirParty::constructFromCommon(custTable);
dirPartyPostalAddressView.LocationName ='Headquarters';
dirPartyPostalAddressView.City ='Victoria Island';
dirPartyPostalAddressView.Street ='Idejo';
dirPartyPostalAddressView.StreetNumber ='15';
dirPartyPostalAddressView.CountryRegionId ='NG';
dirPartyPostalAddressView.State ='LOS';
// Fill address
dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);
dirPartyContactInfo.LocationName ='Financial Derivative Phone Contact';
dirPartyContactInfo.Locator ='551291165837';
dirPartyContactInfo.Type = LogisticsElectronicAddressMethodType::Phone;
dirPartyContactInfo.IsPrimary = NoYes::Yes;
// Fill Contacts
dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
// Marks the end of transaction.
ttsCommit;
}
catch(Exception::Error)
{
ttsAbort;
throw Exception::Error;
}
info("Customer has been created");
}
I don't know why I get the following error even though the record was not previously created in the table. Here is the error:
Microsoft.Dynamics.Ax.Xpp.DuplicateKeyException was unhandled by user code
Message: An exception of type 'Microsoft.Dynamics.Ax.Xpp.DuplicateKeyException' occurred in aoskernel.dll but was not handled in user code
Additional information: Cannot create a record in Customers (CustTable). Name: Financial Derivative.
The record already exists.
What could I be doing wrongly?