Hi,
I am getting below error while updating my entity using datagrid in asp.net,
[FaultException`1: Entity Id must be specified for Update]
please help me to resolve this.
Thanks.
*This post is locked for comments
Hi,
I am getting below error while updating my entity using datagrid in asp.net,
[FaultException`1: Entity Id must be specified for Update]
please help me to resolve this.
Thanks.
*This post is locked for comments
I have same question to connect dyanmics 365 in console application. My code :
using System.ServiceModel;
using System.Runtime.Serialization;
using System.Net;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using System;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Tooling.Connector;
using Microsoft.Xrm.Sdk.Deployment;
namespace ConsoleAppforContact
{
class ContactConsoleApp
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Connecting to Dynamics 365 .....");
string connection = "AuthType=Office365;Username=gizemsolum@gizemsolum2.onmicrosoft.com;Password=Den126*jk;Url=gizemsolum2.crm4.dynamics.com";
CrmServiceClient crmService = new CrmServiceClient(connection);
var service = (IOrganizationService)crmService.OrganizationWebProxyClient != null ? (IOrganizationService)crmService.OrganizationWebProxyClient : (IOrganizationService)crmService.OrganizationServiceProxy;
//If Connection is succeed
if (crmService.IsReady == true)
{
Console.WriteLine("Connection Established Succesfully ....");
Console.WriteLine($"ConnectedOrgFriendlyName: {crmService.ConnectedOrgFriendlyName}");
Console.WriteLine($"ConnectedOrgVersion: {crmService.ConnectedOrgVersion}");
Console.WriteLine($"ConnectedOrgId: {crmService.ConnectedOrgId}");
//QueryExpression for birthdate
var getAge = new QueryExpression("contact");
Console.WriteLine("QueryExpression (line36)");
getAge.ColumnSet = new ColumnSet(true);
Console.WriteLine("getAge.ColumnSet (line38)");
getAge.Criteria = new FilterExpression();
Console.WriteLine("FilterExpression (line40)");
getAge.Criteria.AddCondition("birthdate", ConditionOperator.OnOrAfter, new DateTime(1956, 01, 06));
Console.WriteLine("If birthdate != null (line42)");
EntityCollection contactList = service.RetrieveMultiple(getAge);
Console.WriteLine("RetrieveMultiple (line44)");
var contactEntity = new Entity("contact");
Console.WriteLine("Create entity for contact (line46)");
Console.WriteLine("contactEntity.Id: " + contactEntity.Id);
Entity accountReference = new Entity("contact");
accountReference["accountid"] = Row.AccountId;
int age = 0;
if (contactList.Entities != null && contactList.Entities.Count > 0)
{
Console.WriteLine("contactList.Entities != null (line50): " + contactList.Entities.Count);
foreach (Entity contact in contactList.Entities)
{
Console.WriteLine("foreach in contactList.Entities (line53)");
string name = contact.Contains("firstname") ? (string)contact["firstname"] : null;
string lastname = contact.Contains("lastname") ? (string)contact["lastname"] : null;
Console.WriteLine("name :" + name + " " + lastname);
Console.WriteLine("id of contact: " + contact.Id);
DateTime birth = contact.Contains("birthdate") ? (DateTime)contact["birthdate"] : DateTime.MinValue;
Console.WriteLine("birthdate (line55): " + birth.ToString());
age = DateTime.Now.Year - birth.Year;
Console.WriteLine("age (line57): " + age);
contactEntity["new_age"] = age;
service.Update(contactEntity);
Console.WriteLine("new_age is updated (line60)");
}//end of contactList.Entites foreach
}//end of contactList.Entites!=null if loop
}
else
{
Console.WriteLine("Connection to Dynamics 365 Failed ... ");
}
}
catch (Exception e) {
Console.WriteLine("Error : ",e.Message);
}//end of try&catch
Console.WriteLine("Operation is worked.");
Console.ReadLine();
}//end of Main
}//end of ContactConsoleApp class
}//end of namespace
could you please tell me how to create a record using above code..
string id = guidBox.Text;
Guid guid = Guid.Parse(id);
string itemcode =itmcodeBox.Text;
string itemdesc = itmdescBox.Text;
int quantity = Convert.ToInt32(qtyBox.Text);
int unit = Convert.ToInt32(unitBox.Text);
int no_of_app = Convert.ToInt32(noofappBox.Text);
decimal uprice = Convert.ToDecimal(unitBox.Text);
Money unitprice = new Money(uprice) ;
decimal discount = Convert.ToDecimal(discountBox.Text);
decimal nprice = Convert.ToDecimal(netPriceBox.Text);
Money netprice= new Money(nprice);
// decimal val = quantity * unitprice;
// decimal totalPrice = val - discount;
// Used to update the data source.
intelCRM.Attributes["new_itemcode"] = itemcode;
intelCRM.Attributes["new_intelcrmquotationid"] = guid;
intelCRM.Attributes["new_itemdescription"] = itemdesc;
intelCRM.Attributes["new_quantity"] = quantity;
intelCRM.Attributes["new_numberofapplications"] = unit;
intelCRM.Attributes["new_unit"] = no_of_app;
intelCRM.Attributes["new_discount"] = discount;
intelCRM.Attributes["new_unitprice"] = unitprice.Value;
intelCRM.Attributes["new_netprice"] = netprice.Value;
crmService.Update(intelCRM);
// Switch out of edit mode.
dg_IntelCRM.EditItemIndex = -1;
// dg_IntelCRM.DataBind();
fillgrid();
Response.Write("<script>alert('Your record is updated successfully')</script>");
I am getting below error while executing the above code
System.InvalidCastException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #CF866723
please help me.
Thanks
string id = guidBox.Text; Guid guid = Guid.Parse(id); string itemcode =itmcodeBox.Text; string itemdesc = itmdescBox.Text; int quantity = Convert.ToInt32(qtyBox.Text); int unit = Convert.ToInt32(unitBox.Text); int no_of_app = Convert.ToInt32(noofappBox.Text); Money mon = new Money(unitBox.Text).Value; decimal unitprice = Convert.ToDecimal(unitBox.Text); mon.Value = Convert.ToDecimal(unitPrice); decimal discount = Convert.ToDecimal(discountBox.Text); Money net = new Money(); decimal netPrice = Convert.ToDecimal(netPriceBox.Text); net.Value = Convert.ToDecimal(netPrice); // Use quantity to update the data source. decimal val = quantity * unitprice; decimal totalPrice = val - discount;
In the above code i am getting error at Money field.
Please help me.
you have to pass Money type something like below
myEntity.Attributes["abc_transactionamount"] = new Money((decimal)obj.TotalAmountToPay);
Thanks for reply, i have given Currency datatype for Unit Price, can i give Money data type for the Unit price in asp.net or decimal is enough?
that means you are passing some incorrect datatype to a field. When you are setting the value make sure the dattype in crm matches with what type you are setting.
Now its giving this error
"Incorrect attribute value type System.String"
you are getting the guid but not passing to crm . add below line of code next to
intelCRM.Attributes["new_itemcode"] = itemcode;
intelCRM.Attributes["new_intelcrmquotationid"] = guid ;
i have added it to my datagrid and it is displaying too, but still am getting same error.
here is my code:
protected void dg_IntelCRM_UpdateCommand(object source, DataGridCommandEventArgs e) { var crmService = CRMConnection.GetCRMService(); System.Web.UI.WebControls.TextBox guidBox = e.Item.FindControl("tb_editguid") as System.Web.UI.WebControls.TextBox; System.Web.UI.WebControls.TextBox linenoBox = e.Item.FindControl("tb_editno") as System.Web.UI.WebControls.TextBox; if (linenoBox != null) { string line_number = linenoBox.Text; intelCRM.Attributes["new_name"] = line_number; } else { Response.Write("<script>alert('Error:Null Value ')</script>"); } System.Web.UI.WebControls.TextBox itmcodeBox = e.Item.FindControl("tb_editcode") as System.Web.UI.WebControls.TextBox; System.Web.UI.WebControls.TextBox itmdescBox = e.Item.FindControl("tb_editdesc") as System.Web.UI.WebControls.TextBox; System.Web.UI.WebControls.TextBox qtyBox = e.Item.FindControl("tb_editqty") as System.Web.UI.WebControls.TextBox; System.Web.UI.WebControls.TextBox unitBox = e.Item.FindControl("tb_editunit") as System.Web.UI.WebControls.TextBox; System.Web.UI.WebControls.TextBox noofappBox = e.Item.FindControl("tb_editno_of_app") as System.Web.UI.WebControls.TextBox; System.Web.UI.WebControls.TextBox unitpriceBox = e.Item.FindControl("tb_editunitprice") as System.Web.UI.WebControls.TextBox; System.Web.UI.WebControls.TextBox discountBox = e.Item.FindControl("tb_editdis") as System.Web.UI.WebControls.TextBox; System.Web.UI.WebControls.TextBox netPriceBox = e.Item.FindControl("tb_editnetprice") as System.Web.UI.WebControls.TextBox; // Extract the data from the Textbox to string. string id = guidBox.Text; Guid guid = new Guid(id); string itemcode =itmcodeBox.Text; string itemdesc = itmdescBox.Text; int quantity = Convert.ToInt32(qtyBox.Text); int unit = Convert.ToInt32(unitBox.Text); string no_of_app = noofappBox.Text; decimal unitprice = Convert.ToDecimal(unitBox.Text); decimal discount = Convert.ToDecimal(discountBox.Text); decimal netPrice = Convert.ToDecimal(netPriceBox.Text); // Use quantity to update the data source. decimal val = quantity * unitprice; decimal totalPrice = val - discount; // Used to update the data source. intelCRM.Attributes["new_itemcode"] = itemcode; intelCRM.Attributes["new_itemdescription"] = itemdesc; intelCRM.Attributes["new_quantity"] = quantity; intelCRM.Attributes["new_numberofapplications"] = unit; intelCRM.Attributes["new_unit"] = no_of_app; intelCRM.Attributes["new_discount"] = unitprice; intelCRM.Attributes["new_unitprice"] = discount; intelCRM.Attributes["new_netprice"] = totalPrice; crmService.Update(intelCRM); // Switch out of edit mode. dg_IntelCRM.EditItemIndex = -1; // dg_IntelCRM.DataBind(); fillgrid(); }
Thanks
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,235 Most Valuable Professional
nmaenpaa 101,156