SALES ORDER INTEGRATION WITH CRM : AX 2012
SEND CONFIRMED SALES ORDER TO CRM
public void run()
{
compSalesInvoicetoCRMUat.compSalesInvoiceReference.SalesInvoiceClient service;
compSalesInvoicetoCRMUat.compSalesInvoiceReference.ISalesInvoice salesinvoice;
CustInvoiceJour custInvoiceJour,custInvoiceJourupd;
CustInvoiceTrans custInvoiceTrans;
InventDim inventDim;
InventTrans inventTrans;
InventTable inventTable,inventTablechar;
ConfigChoice configChoice;
str success;
int qty;
// int x=1;
System.Exception ex;
System.Type type;
compProductMasterDefault prodMasterDef;
select * from prodMasterDef;
changeCompany(prodMasterDef.DealerCompany)
{
while select custInvoiceJour
join custInvoiceTrans where custInvoiceJour.SalesId == custInvoiceTrans.SalesId
&& custInvoiceJour.comp_IsInvoiceSent == NoYes::No
&& custInvoiceJour.InvoiceId == custInvoiceTrans.InvoiceId
join inventTable where inventTable.ItemId == custInvoiceTrans.ItemId
{
try
{
type = CLRInterop::getType('compSalesInvoicetoCRMUat.compSalesInvoiceReference.SalesInvoiceClient');
service = AifUtil::createServiceClient(type);
inventDim.clear();
select inventTrans where custInvoiceTrans.InvoiceId == inventTrans.InvoiceId;
select inventDim where inventTrans.InventDimId == inventDim.inventDimId;
success = service.Synchronize_Invoice(custInvoiceJour.SalesId,custInvoiceJour.InvoiceId,custInvoiceJour.InvoiceAccount,custInvoiceTrans.ItemId,custInvoiceTrans.SalesPrice,inventDim.inventSerialId,real2int(custInvoiceTrans.Qty),custInvoiceJour.InvoiceAmount,custInvoiceJour.SumTax,custInvoiceJour.invoicedate);
info(strFmt("%1-%2-%3-%4-%5-%6-%7-%8-%9-%10",custInvoiceJour.SalesId,custInvoiceJour.InvoiceId,custInvoiceJour.InvoiceAccount,custInvoiceTrans.ItemId,custInvoiceTrans.SalesPrice,inventDim.inventSerialId,real2int(custInvoiceTrans.Qty),custInvoiceJour.InvoiceAmount,custInvoiceJour.SumTax,custInvoiceJour.invoicedate));
if(success != "Success")
{
error(strFmt("Error %1 for SO %2",success,custInvoiceJour.SalesId));
}
else
{
ttsBegin;
select forUpdate custInvoiceJourupd where custInvoiceJourupd.InvoiceId == custInvoiceJour.InvoiceId;
custInvoiceJourupd.comp_IsInvoiceSent = NoYes::Yes;
custInvoiceJourupd.update();
ttsCommit;
info(strFmt("Sales Invoice %1 is created in CRM",custInvoiceJour.SalesId));
}
}//try
catch(Exception::CLRError)
{
ex = CLRInterop::getLastException();
info(CLRInterop::getAnyTypeForObject(ex.ToString()));
}
comp_RetailExceptionActivityLog::logEvent(strFmt('Sales Invoice ID:',custInvoiceJour.SalesId),infolog.export());
}//while
// comp_RetailExceptionActivityLog::logEvent('Product Import',infolog.export());
}
}
SEND CONFIRMED SALES ORDER TO CRM
public void run()
{
compSalesInvoicetoCRMUat.compSalesInvoiceReference.SalesInvoiceClient service;
compSalesInvoicetoCRMUat.compSalesInvoiceReference.ISalesInvoice salesinvoice;
CustInvoiceJour custInvoiceJour,custInvoiceJourupd;
CustInvoiceTrans custInvoiceTrans;
InventDim inventDim;
InventTrans inventTrans;
InventTable inventTable,inventTablechar;
ConfigChoice configChoice;
str success;
int qty;
// int x=1;
System.Exception ex;
System.Type type;
compProductMasterDefault prodMasterDef;
select * from prodMasterDef;
changeCompany(prodMasterDef.DealerCompany)
{
while select custInvoiceJour
join custInvoiceTrans where custInvoiceJour.SalesId == custInvoiceTrans.SalesId
&& custInvoiceJour.comp_IsInvoiceSent == NoYes::No
&& custInvoiceJour.InvoiceId == custInvoiceTrans.InvoiceId
join inventTable where inventTable.ItemId == custInvoiceTrans.ItemId
{
try
{
type = CLRInterop::getType('compSalesInvoicetoCRMUat.compSalesInvoiceReference.SalesInvoiceClient');
service = AifUtil::createServiceClient(type);
inventDim.clear();
select inventTrans where custInvoiceTrans.InvoiceId == inventTrans.InvoiceId;
select inventDim where inventTrans.InventDimId == inventDim.inventDimId;
success = service.Synchronize_Invoice(custInvoiceJour.SalesId,custInvoiceJour.InvoiceId,custInvoiceJour.InvoiceAccount,custInvoiceTrans.ItemId,custInvoiceTrans.SalesPrice,inventDim.inventSerialId,real2int(custInvoiceTrans.Qty),custInvoiceJour.InvoiceAmount,custInvoiceJour.SumTax,custInvoiceJour.invoicedate);
info(strFmt("%1-%2-%3-%4-%5-%6-%7-%8-%9-%10",custInvoiceJour.SalesId,custInvoiceJour.InvoiceId,custInvoiceJour.InvoiceAccount,custInvoiceTrans.ItemId,custInvoiceTrans.SalesPrice,inventDim.inventSerialId,real2int(custInvoiceTrans.Qty),custInvoiceJour.InvoiceAmount,custInvoiceJour.SumTax,custInvoiceJour.invoicedate));
if(success != "Success")
{
error(strFmt("Error %1 for SO %2",success,custInvoiceJour.SalesId));
}
else
{
ttsBegin;
select forUpdate custInvoiceJourupd where custInvoiceJourupd.InvoiceId == custInvoiceJour.InvoiceId;
custInvoiceJourupd.comp_IsInvoiceSent = NoYes::Yes;
custInvoiceJourupd.update();
ttsCommit;
info(strFmt("Sales Invoice %1 is created in CRM",custInvoiceJour.SalesId));
}
}//try
catch(Exception::CLRError)
{
ex = CLRInterop::getLastException();
info(CLRInterop::getAnyTypeForObject(ex.ToString()));
}
comp_RetailExceptionActivityLog::logEvent(strFmt('Sales Invoice ID:',custInvoiceJour.SalesId),infolog.export());
}//while
// comp_RetailExceptionActivityLog::logEvent('Product Import',infolog.export());
}
}
No comments:
Post a Comment