locked
CRM 2011 on premise:opportunity entity doesnt contain attribute with Name=aco_dsagent RRS feed

  • Question

  • I'm trying to create an opportunity via a C# console, however, when I'm trying to set a custom lookup field, I'm getting the above error. The field is definitely in the CRM proxy file, so I don't know why it can't find it.

    Opportunity newOpp = new Opportunity();
    EntityReference opportunityagentValue = new EntityReference("aco_dsagent", new Guid(agent.Id.ToString())); // This guid has a valid value
    newOpp.aco_DSAgent = opportunityagentValue; // newOpp.aco_DSAgent is what came up for my intellisense, from the proxy class. However, the error is saying it does not contain the attribye 'aco_dsagent', ie. with lower case.
    
    Guid newOppId = this.crmService.Create(newOpp);

    Code from CRM proxy class (this class is included in my project)

    /// <summary>
    /// Unique identifier for DS Agent associated with Opportunity.
    /// </summary>
    [Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("aco_dsagent")]
    public Microsoft.Xrm.Sdk.EntityReference aco_DSAgent
    {
    	get
    	{
    		return this.GetAttributeValue<Microsoft.Xrm.Sdk.EntityReference>("aco_dsagent");
    	}
    	set
    	{
    		this.OnPropertyChanging("aco_DSAgent");
    		this.SetAttributeValue("aco_dsagent", value);
    		this.OnPropertyChanged("aco_DSAgent");
    	}
    }


    Any ideas? Thanks.


    Monday, April 10, 2017 4:35 PM

Answers

  • Hi,

    Try changing the below line

    EntityReference opportunityagentValue = new EntityReference("aco_dsagent", new Guid(agent.Id.ToString()));

    to this:

    EntityReference opportunityagentValue = new EntityReference(aco_DSAgent.EntityLogicalName, new Guid(agent.Id.ToString()));

    Thanks


    Sachith Chandrasiri

    Monday, April 10, 2017 11:25 PM

All replies

  • Hi,

    Try changing the below line

    EntityReference opportunityagentValue = new EntityReference("aco_dsagent", new Guid(agent.Id.ToString()));

    to this:

    EntityReference opportunityagentValue = new EntityReference(aco_DSAgent.EntityLogicalName, new Guid(agent.Id.ToString()));

    Thanks


    Sachith Chandrasiri

    Monday, April 10, 2017 11:25 PM
  • Thanks for your reply, that fixed it for me!


    Tuesday, April 11, 2017 8:20 AM