Required element 'LogicalName' is missing for field 'Target'

I am using Microsoft XRM SDK to add an object programmatically. However, every time I run the command .Create()

, I get the following error:

Required member 'LogicalName' missing for field 'Target'

      

This is the first time the use of this service and similar resources in our company is limited, so I'm not sure what this error means or how to investigate / solve it.

Below is the class I created to handle XRM communication. I create an instance of each of the connection properties in the constructor. Then, in this case, call CreateAgency(AgentTransmission agt)

. The exception is a method CreateAgency()

when calling a method .Create(account)

.

class DynamicsCommunication
{
    private Uri OrganizationUri = new Uri("http://devhildy03/xRMDRMu01/XRMServices/2011/Organization.svc");
    private ClientCredentials credentials;
    private OrganizationServiceProxy servicePoxy;
    private Guid accountId;
    private Entity account;

    public DynamicsCommunication()
    {
        credentials = new ClientCredentials();
        credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
        servicePoxy = new OrganizationServiceProxy(OrganizationUri, null, credentials, null);
        accountId = Guid.Empty;
    }

    public string UpdateDynamics(AgentTransmission agt)
    {
        switch (DeterminAction(agt))
        {
            case DynamicsAction.Create:
                return CreateAgency(agt);
            case DynamicsAction.Update:
                return UpdateAgency(agt);
            default:
                return string.Empty;
        }
    }

    private string CreateAgency(AgentTransmission agt)
    {
        try
        {
            //Exception is thrown after this command
            accountId = servicePoxy.Create(CreateAccount(agt));

            if (accountId != Guid.Empty)
            {
                return string.Empty;
            }
            else
            {
                return "error creating agency";
            }
        }
        catch (ODataException oEx)
        {
            string s = oEx.Message;
            throw;
        }
        catch (Exception ex)
        {
            string s = ex.Message;
            throw;
        }
    }

    private Entity CreateAccount(AgentTransmission agt)
    {
        account = new Entity();
        account.Attributes.Add("LogicalName", "something");
        account.Attributes.Add("name", agt.AgencyName);
        account.Attributes.Add("telephone1", agt.BusinessPhone.Replace("(","").Replace(")", "").Replace("-", ""));
        account.Attributes.Add("address1_line1", agt.MailingStreet1);
        account.Attributes.Add("address1_city", agt.MailingCity);
        account.Attributes.Add("address1_postalcode", agt.MailingZip);
        account.Attributes.Add("neu_address1stateprovince", 1); //1 for Mailing
        account.Attributes.Add("neu_channelid", LookupChannelId(agt.Channel));
        account.Attributes.Add("neu_appointementstatus", "279660000");
        account.Attributes.Add("customertypecode", LookupCustomerCode(agt.RelationshipType));
        account.Attributes.Add("neu_taxid", UnobfuscateRef(agt.ReferenceNumber));

        return account;
    }
}

      

+3


source to share


1 answer


Set the name of the CRM object in the LogicalName property of the Entity instead of adding it to the attribute collection

account = new Entity("your_entity_name");

      



or

account = new Entity();
account.LogicalName = "your_entity_name";

      

+5


source







All Articles