Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 72043

catch duplicate key exception D365

$
0
0

For D365 Update 9, I am attempting to suppress an error message for the Exception::DuplicateKeyException. (If there is a duplicate key I want to continue the thread of code without inserting the record).   My code works in that it will continue to process related code without inserting the record however I am unable to suppress the error log. My code is here:

void createTaxcode(TaxGroup _newTaxGroup,LogisticsPostalAddress _deliveryAddress )

{

TaxGroupHeading newTaxGroupHeading; //Sales Tax Group

TaxGroupName name;

TaxTable newTaxTable; //Sales Tax Code

TaxData newTaxData; //Sales Tax code value

TaxGroupData newTaxGroupData; //Sales Tax code group assignment

TaxOnItem newTaxOnItem; //Item tax group

;

if(_deliveryAddress.CountryRegionId=="USA") //only create tax codes for US addresses.

{

if(strLen(_newTaxGroup)==9)

{

name = strFmt("%1 %2 %3",_deliveryAddress.ZipCode,_deliveryAddress.State,_deliveryAddress.City);

try

{

ttsbegin;

newTaxGroupHeading.initValue();

newTaxGroupHeading.TaxGroup = _newTaxGroup;

newTaxGroupHeading.TaxGroupName = name;

newTaxGroupHeading.insert();

newTaxTable.TaxCode = _newTaxGroup;

newTaxTable.TaxName = Name;

newTaxTable.TaxAccountGroup = 'PDI';

newTaxTable.TaxCurrencyCode = 'USD';

newTaxTable.TaxRoundOff = 1.00;

newTaxTable.TaxRoundOffType = RoundOffType::RoundUp;

newTaxTable.TaxPeriod = _deliveryAddress.State;

newTaxTable.insert();

newTaxData.initValue();

newTaxData.TaxCode = newTaxTable.TaxCode;

newTaxData.TaxValue = 1.00;

newTaxData.insert();

newTaxGroupData.TaxGroup = newTaxGroupHeading.TaxGroup;

newTaxGroupData.TaxCode = newTaxTable.TaxCode;

newTaxGroupData.insert();

//add the new tax code to the ALL item tax group.

newTaxOnItem.TaxItemGroup = 'ALL';

newTaxOnItem.TaxCode = newTaxGroupData.TaxCode;

newTaxOnItem.insert();

ttscommit;

}

catch(Exception::DuplicateKeyExceptionNotRecovered)

{

warning("Not recovered");

}

catch (Exception::DuplicateKeyException)

{

ttsabort;

}

}

else

{

error(strFmt("Unable to create tax code %1",_newTaxGroup)); //error if we didn't get zip + 4

}

}

}


Viewing all articles
Browse latest Browse all 72043

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>