How to get OwnerId of ERP Customer Number in CRM Online?.
-
Wednesday, May 09, 2012 1:58 PM
Hi,
I am using C#.net code to insert data from DB2 to CRM Online.
Here i have to get Owner Id of ERP customer Number and have to insert the same into Invoice entity. Please help me out.
Here is the code for reference
EntityReference
erCustomer = newEntityReference();
EntityReferenceerCurrency = newEntityReference();
EntityReferenceerPriceList = newEntityReference();
erCustomer.Id =
newGuid("{"+ customerAccount.Keys[0] + "}");
OptionSetValueos = newOptionSetValue();
os.Value =
Int32.Parse(invoice.ERPCompanyName);
erCurrency.Id =
newGuid("{"+ currencyList[invoiceDetails.ItemCurrency] + "}");
erPriceList.Id =
newGuid("{"+ priceList[invoiceDetails.ItemPriceList] + "}");
Invoiceinv = newInvoice();
inv.Name = invoice.InvoiceNumber +
" : "+ invoice.InvoiceDate + " : "+ optionSetList[invoice.ERPCompanyName];
inv.CustomerId = erAccount;
inv.dnt_ERPBillToCustomerNumberId = erCustomer;
inv.dnt_ERPCompanyName = os;
inv.dnt_ERPInvoiceNumber = invoice.InvoiceNumber;
inv.TransactionCurrencyId = erCurrency;
inv.PriceLevelId = erPriceList;
DateTimedt = DateTime.Parse(invoice.InvoiceDate.Substring(4, 2) + "-"+ invoice.InvoiceDate.Substring(6, 2) + "-"+ invoice.InvoiceDate.Substring(0, 4));
inv.dnt_InvoiceDate = dt;
inv.dnt_InvoiceYear =
Int32.Parse(invoice.InvoiceYear);
inv.dnt_InvoicePrefix = invoice.InvoicPFX;
EntityCollectionecProducts = newEntityCollection();
ecProducts.EntityName =
InvoiceDetail.EntityLogicalName;
foreach(InvoicesInvoiceInvoiceProductinvProduct ininvoice.InvoiceProduct)
{
InvoiceDetailiProd = newInvoiceDetail();
iProd.dnt_AccountId = erAccount;
iProd.dnt_ERPBillToCustomerNumberId = erCustomer;
iProd.dnt_ERPCompanyName = os;
iProd.dnt_ERPInvoiceNumber = invoice.InvoiceNumber;
iProd.dnt_InvoiceDate = dt;
QueryExpressionqeProduct = newQueryExpression();
qeProduct.EntityName =
"product";
qeProduct.ColumnSet =
newColumnSet("productid", "productnumber");
ConditionExpressioncon = newConditionExpression();
con.AttributeName =
"productnumber";
con.Operator =
ConditionOperator.Equal;
con.Values.Add(invProduct.Product);
FilterExpressionfil = newFilterExpression();
fil.FilterOperator =
LogicalOperator.And;
fil.Conditions.Add(con);
qeProduct.Criteria = fil;
EntityCollectionecItem = _serviceProxy.RetrieveMultiple(qeProduct);
EntityReferenceerProd = newEntityReference();
EntityReferenceerUnit = newEntityReference();
EntityReferenceerPClass = newEntityReference();
if(ecItem.Entities.Count > 0)
{
erProd.Id =
newGuid("{"+ ecItem.Entities[0]["productid"].ToString() + "}");
iProd.ProductId = erProd;
}
else
{
thrownewException("Product does not exist");
}
erUnit.Id =
newGuid("{"+ unitList[invProduct.Unit] + "}");
iProd.UoMId = erUnit;
if(productClassList.AllKeys.Contains(invProduct.ItemClass))
{
erPClass.Id =
newGuid("{"+ productClassList[invProduct.ItemClass] + "}");
}
else
{
erPClass.Id =
newGuid("{"+ GetProductClassBasedOnProductClassName(invProduct.ItemClass) + "}");
}
iProd.dnt_ProductClassId = erPClass;
iProd.Quantity =
decimal.Parse(invProduct.Quantity);
Moneymoney = newMoney();
money.Value =
decimal.Parse(invProduct.Price);
iProd.PricePerUnit = money;
iProd.IsProductOverridden =
false;
iProd.IsPriceOverridden =
true;
ecProducts.Entities.Add(iProd);
}
inv.RelatedEntities.Add(
newRelationship("invoice_details"), ecProducts);
_serviceProxy.Create(inv);
ravindra
All Replies
-
Wednesday, May 09, 2012 2:35 PMPlease tell us the error that occur when you run the code
Proper way to set the Guid is without {} signs and make sure the GUID is in proper format 32 Digits
ie. 4FFA9853-748F-E111-9A0D-1CC1DEE89A06
erPClass.Id =new Guid(GetProductClassBasedOnProductClassName(invProduct.ItemClass));
I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Mubasher Sharif
Check out my about.me profile!
http://mubashersharif.blogspot.com
Linked-In Profile
Follow me on Twitter!
- Edited by MubasherSharif Wednesday, May 09, 2012 2:36 PM