Search code examples
c#asp.netdynamics-crm-2011dynamics-crmcrm

Error in Saving of Regarding Attribute (Lead_PhoneCall Activity) from CRM Portal (2011)?


I am trying to save Guid of Lead in Regarding Field of PhoneCall Activity, It gives an error like - "regardingobjectid" only. [On Premise]

Please Help!

In New_PhoneCall.cs Page :

PhoneCall_Save.regardingobjectid = Guid.Parse(hdnfld_regarding.Value); //(hdnfld_regarding is a hiddenfield in which m passing guid, which i have taken along with textbox)

In AppCode/CRMDMLibrary.cs :

    public class PhoneEntity
    {
       public Guid regardingobjectid;
    }

    public bool SaveNewPhoneCall()
    {
        try
        {
            IOrganizationService Context = CRMDMLibrary.GetCRMService(url, DomainName, username, password);

            Entity Phone = new Entity("phonecall");

            Phone["regardingobjectid"] = new EntityReference("regardingobject", regardingobjectid);

            Guid phoneid = Context.Create(Phone);
            return true;
        }
        catch (Exception ex)
        {
            HttpContext.Current.Response.Write(ex.Message);
            HttpContext.Current.Response.End();
            return false;
        }

    }

Solution

  • Passing regardingobject as EntityReference is wrong.You should pass lead as EntityReference

     Phone.Attributes["regardingobjectid"] = new EntityReference("lead", regardingobjectid);
    

    Also Check that where lead id is coming from