locked
Trying to update contact.parentcustomerid - The entity with a name = '8' was not found in the MetadataCache RRS feed

  • Question

  • Hi,

    I am trying to create an account and assign it to a contact via the parentcustomerid field. Here is my code:

            public void CreateAccountForContact(contact c, ContactState state)
            {
                var acct = new account();
                acct.statecode = new AccountStateInfo();
                switch (state)
                {
                    case ContactState.Active:
                        acct.statecode.Value = AccountState.Active;
                        break;
                    case ContactState.Inactive:
                        acct.statecode.Value = AccountState.Inactive;
                        break;
                }
                acct.primarycontactid = new Lookup();
                acct.primarycontactid.Value = c.contactid.Value;
                acct.primarycontactid.type = EntityName.contact.ToString();
                Guid acctID = this.MainDataService.Create(acct);

                var target = new TargetUpdateContact();
                c.parentcustomerid = new Customer();
                c.parentcustomerid.Value = acctID;
                c.parentcustomerid.type = EntityName.account.ToString();
                target.Contact = c;

                var request = new UpdateRequest();
                request.Target = target;

                this.MainDataService.Execute(request);
            }

    I recieve a "Server was unable to process request" and when I delve into the innerText of the error it states "The entity with a name = '8' was not found in the MetadataCache".

    Anyone have any idea's as to why this is happening?

    Thanks,
    James.
    Wednesday, February 18, 2009 1:02 PM

Answers

  •  Try creating a new contact object, and assign it only the parentcustomer value and the contactID field, and the update it. I think you might have a problem that the contactobject you are trying to send in has been fetched from CRM, and all other lookups has the numerical value of the type-enums set instead of the string-value.


    Like this:

    ....
                 var target = new TargetUpdateContact();
                contact cToUpdate=new contact();
                cToUpdate.contactid=new Key();
                cToUpdate.contactID.Value=c.contactid.value;
                
                cToUpdate.parentcustomerid = new Customer();
                cToUpdate.parentcustomerid.Value = acctID;
                cToUpdate.parentcustomerid.type = EntityName.account.ToString();
                target.Contact = cToUpdate;

                var request = new UpdateRequest();
                request.Target = target;

                this.MainDataService.Execute(request);
            }
    • Marked as answer by jhowe11 Thursday, February 19, 2009 1:53 PM
    Thursday, February 19, 2009 12:59 PM

All replies

  • I'm not sure that you can set the state in the create method. You might have to send a SetStateAccountRequest after creating the account.

     

    Wednesday, February 18, 2009 9:30 PM
  •  Can you update an account if it is Inactive?
    Wednesday, February 18, 2009 11:20 PM
  • Hi Jens,

    You are right you cannot update an account directly (I should have picked up on this as I have came across this issue beforehand!). I will attempt to update the status of the account first, and then update the parentcustomerid field.

    Andy,

    I am unsure of whether updating a disabled account will be an issue I will soon find out!

    Will keep you posted.

    James.
    Thursday, February 19, 2009 9:04 AM
  • Turns out that wasnt the problem afterall. I have the account updating correctly now however, when it comes to actually updating the Contact's parentcustomerid field, I get the error again!
    Thursday, February 19, 2009 9:40 AM
  •  Try creating a new contact object, and assign it only the parentcustomer value and the contactID field, and the update it. I think you might have a problem that the contactobject you are trying to send in has been fetched from CRM, and all other lookups has the numerical value of the type-enums set instead of the string-value.


    Like this:

    ....
                 var target = new TargetUpdateContact();
                contact cToUpdate=new contact();
                cToUpdate.contactid=new Key();
                cToUpdate.contactID.Value=c.contactid.value;
                
                cToUpdate.parentcustomerid = new Customer();
                cToUpdate.parentcustomerid.Value = acctID;
                cToUpdate.parentcustomerid.type = EntityName.account.ToString();
                target.Contact = cToUpdate;

                var request = new UpdateRequest();
                request.Target = target;

                this.MainDataService.Execute(request);
            }
    • Marked as answer by jhowe11 Thursday, February 19, 2009 1:53 PM
    Thursday, February 19, 2009 12:59 PM
  • Jens,

    Your solution worked!! thank you.

    However, I am pretty sure I had already tried creating a new contact and only updating the relevant fields earlier and it didn't work....strange!

    Cheers,
    James.
    Thursday, February 19, 2009 1:53 PM