Saturday 21 December 2013

Merging two records in ax 2012

static void LedgerReasonMerge(Args _args)
{
ReasonTable reasonTableDelete;
ReasonTable reasonTable;
ttsBegin;
select firstOnly forUpdate reasonTableDelete
where reasonTableDelete.Reason == 'COUNTER';
select firstOnly forUpdate reasonTable
where reasonTable.Reason == 'AUCTION';
reasonTableDelete.merge(reasonTable);
reasonTable.doUpdate();
reasonTableDelete.doDelete();
ttsCommit;

Customer records merge:-

 CustTable               custTable;
 CustTable               custTableDelete;
 salesJournalAutoSummary jourSummary;
 ;
 ttsbegin;
 delete_from jourSummary  where jourSummary.CustAccount == '101';
 select firstonly forupdate CustTableDelete where CustTableDelete.AccountNum == '101';
 select firstonly forupdate custTable where CustTable.AccountNum == '105';
 custTableDelete.merge(custTable);
 custTable.doUpdate();
 custTableDelete.doDelete();

 ttscommit;

Getting like this error :-Cannot edit a record in Sales summary update (SalesJournalAutoSummary). Form: None, Customer.
The record already exists.
Sol:-
if u get this type of error means check in your sql in this table "salesjournalautosummary" 
you have 101 records in other company please delete it form data base (or) by query form ax.

form sql we have to delete those customer accounts 

select * from SalesJournalAutoSummary where CUSTACCOUNT ='101'
select * from SalesJournalAutoSummary where CUSTACCOUNT ='102'
select * from SalesJournalAutoSummary where CUSTACCOUNT ='103'

delete SalesJournalAutoSummary where CUSTACCOUNT in ('CustfromACC',
'101',
'102',

'103')

No comments:

Post a Comment