0
Entity contact = new Entity("contact");
contact.Attributes.Add("fullname", "h api test");
contact.Attributes.Add("emailaddress1", "hh@devenv1.local");
contact.Attributes.Add("telephone1", "1");

contact.Attributes["parentcusotmerid"] = new EntityReference("Organization", );

Guid contactId = m_OrgServ.Create(contact);
Console.WriteLine(contactId);

The lookup field I want to set

The logicalname of the lookup field is parentcusotmerid, and

m_OrgSerc.create 

is basically

Service.create

I am setting attribute values for the fields, it works fine for normal text boxes where I am entering values, however for lookup values it doesn't work. I know lookup fields are of type EntityReference, so I need to know the LogicalName of the entity the lookup is pointing and the Id of the record.

I have tried it but its asking for the GUID of the Organization field now, so I'm not sure if I am going about it the right way?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
HH44
  • 15
  • 1
  • 2
  • 10
  • "parentcustomerid" is a lookup to account and contact so you have to use either of the entities logical name to assign lookup value. If you have renamed the account entity to organization then its only the display name which is changed the schema name remains the same. Are you trying associated account record with the current contact? – ntn May 23 '20 at 15:26
  • @Nitin I am just trying to create a contact... so I want to set the lookup field to a value. The organization is already created, I just want to associate that to this contact that I am creating. Sorry is this what you were asking ? – HH44 May 23 '20 at 16:30
  • @HH44 You cannot set "parentcustomerid" to organization. It's special reference field that takes either Account or Contact entity reference as parameter. – minohimself May 23 '20 at 17:21

1 Answers1

2

You cannot set "parentcustomerid" to organization. It's special reference field that takes either Account or Contact entity reference as parameter.

If you want to set it you go like this

contact.Attributes["parentcusotmerid"] = new EntityReference("account", Guid.NewGuid());

or

contact.Attributes["parentcusotmerid"] = new EntityReference("contact", Guid.NewGuid());

where Guid.NewGuid() is Guid of your Account or Contact that you want to reference

minohimself
  • 496
  • 3
  • 9
  • But as you can see from the image I have upload .. I want to set the "organization name" field which is "parentcustomerid" to the value "BAE Systems plc" ... so where in this code that you have given can I specify that .. so that is the value that is looked at and chosen ? – HH44 May 23 '20 at 20:51
  • @HH44 you renamed the parent customer lookup as organisation, if you already created the “BAE systems” account record, you have to get the guid of that record. The guid with entity reference is the only way to set it. We cannot set with just name. – Arun Vinoth-Precog Tech - MVP May 24 '20 at 04:04
  • As Arun said you would set referenz to Account with the GUID of the BAE systems record if it already exists – minohimself May 24 '20 at 08:31