Monday, March 14, 2011 5:36 PM
I have the Customer Portal up and running and am implementing a custom Entity form (Expenses). I am able to succussefully create new records with every field type except Lookup fields. I am able to pull the correct values for the Lookup dropdown field using FetchXML, but am having trouble getting that field to save correctly. I am getting a "cannot implicitly convert type 'string' to Microsoft.xrm.client.CRMEntityReference" error in visual studio. The actual code for setting this attribute is (new_budgetlineid = BudgetLineType.SelectedValue,). That works fine for option sets, but not for lookup values.
Also, if I try and use a CRM form in .NET, it just ignores any lookup fields and does not display them on the generated form. I found that a bit odd since that kind of defeats the purpose of being able to use those CRM forms in .NET if lookup fields are not supported.
Is there a trick to passing values to these lookup fields? I'm fairly new to CRM development. This is on the release version of CRM 2011.
Tuesday, March 22, 2011 6:11 PMOwner
Lookup fields are currently not supported by default in the CrmEntityFormView so they will just be ignored. There are ways to use lookups, but it requires a little bit of development.
When setting lookups in the service context, they will always need to be passed as EntityReferences. Basically, an ID on its own is not always enough for the CRM to set a lookup. It needs to know the entity type as well. Seeing as you probably know what your entity type is, you can use:
new_budgetlineid = new EntityReference(“entityName”, new Guid(BudgetLineType.SelectedValue));
The other option for setting lookups is: if you have the entity, then you can use the ToEntityReference() method. Since you’re using a dropdown you probably won't use this option.
new_budgetlineid = budgetLine.ToEntityReference;