Hi All,
I have Silverlight plugin inside Account Entity which interacts with another software and brings some values and updates CRM database based on Accountid.
Piece of code is shown below:
private void BeginUpdateAccountToPromoteToMoa(int custId, double tax)
{
string _AccId = ServerUtility.GetCurrentEntityId();
try
{
Guid GID = new Guid(_AccId);
Account updatedAccount = new Account();
EntityDescriptor descriptor = null;
if (GID != Guid.Empty)
{
descriptor = _context.Entities.FirstOrDefault(entity => !String.IsNullOrEmpty(entity.Identity) && new Regex(@"^.*'(" + GID + ")+'.*$", RegexOptions.CultureInvariant
| RegexOptions.IgnoreCase).IsMatch(entity.Identity));
if (descriptor != null && descriptor.Entity != null)
{
Debug.Assert(_context.Detach(descriptor.Entity), String.Format("Cannot detach record with URI: {0}", descriptor.Identity));
}
}
updatedAccount.New_IsIntegrated = true;
updatedAccount.New_SourceId = System.Convert.ToString(custId);
updatedAccount.New_TaxGroup = taxGroupNameText;
updatedAccount.New_taxpercentage = System.Convert.ToDecimal(tax);
updatedAccount.AccountId = GID;
_context.AttachTo("AccountSet", updatedAccount);
_context.UpdateObject(updatedAccount);
_context.BeginSaveChanges(OnUpdateAccountToPromoteToMoaComplete, updatedAccount);
}
catch (SystemException se)
{
_syncContext.Send(new SendOrPostCallback(showErrorDetails), se);
}
}
private void OnUpdateAccountToPromoteToMoaComplete(IAsyncResult result)
{
try
{
_context.EndSaveChanges(result);
}
catch (SystemException se)
{
HtmlPage.Window.Alert(se.ToString());
}
}
But inside database fields are not updated with respect to AccountId(GUID) instead new record is generated with this AccountId along with above mentioned fields and all other previously existing field information will become null.
Please give some solution on this.
Thanks in advance.
blrSvsTech