martedì 22 maggio 2012 14:30
I'm sure someone can help me out here, I'm really much ripping my hair out
why my code below doesn't work. Basically I have a custom entity wich has a list
(and all its list members inside the list) with my custom entity(registerd on
post-create) I create another list which imports all those list members into
another list. Now I need to retrieve the entityID for each list member (in order
for me to add them) My code below (just for one list member for testing
// GET LIST MEMBER QueryByAttribute query = new QueryByAttribute("listmember"); query.AddAttributeValue("listid", m_list_ID.Id); ColumnSet cs = new ColumnSet(); cs.AddColumns("entityid"); query.ColumnSet = cs; EntityCollection entityCollection = service.RetrieveMultiple(query); Guid g = Guid.Empty; g = (Guid)entityCollection.Entities.Attributes["entityid"];
To check the guid I output the GUID on another field as a string just to
check if it has th right one, but when I try to save the form I get the error
"System.InvalidCastException: Specified cast is not valid.". On another note, which is quite strange to me is
when I try the same with "listmemberid" which is also in listmember table I get the GUID, its just when I try
to grab the entityId I get this error.
Tutte le risposte
martedì 22 maggio 2012 23:13
Hi A Roben,
The entityid attribute is actually returning EntityReference object (not Guid).
So to get the actual Guid of the EntityId, you would have to convert the Attribute to EntityReference and access the Id property of it.
g = ((EntityReference)entityCollection.Entities.Attributes["entityid"]).Id;
I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Dimaz Pramudya - CRM Developer - CSG (Melbourne) www.xrmbits.com http://twitter.com/xrmbits
- Proposto come risposta Dimaz Pramudya (www.xrmbits.com) martedì 22 maggio 2012 23:13