How to create a entity record with a "partylist" data type field, through c# code?
i have a entity which has the "to" field of type party list, how do i create the record? through code
*This post is locked for comments
Hi Rahul,
Please use below post : stackoverflow.com/.../create-activityparty-in-crm-without-early-bound-entities
Hello,
Check following - www.magnetismsolutions.com/.../working-with-dynamics-crm-activity-party-lists-in-c--plugins
Try below code snippet:
Entity partyListEntity= new Entity();
partyListEntity= new Entity("activityparty");
partyListEntity["partyid"] = new EntityReference("systemuser", new Guid("CE08EE7F-4F36-E111-B6F6-0050569838D6"));
or
partyListEntity["addressused"] = "arpit.crmconsultant@gmail.com";Entity[] aryTo = { partyListEntity};emailCreate["to"] = aryTo;
Mark this is an answer If it helps.
CheersArpithttps://arpitmscrmhunt.blogspot.in
Hi Guys,
thanks for your help, my requirement is like this -
I have to retrieve a record from CRM, which contains few fields with data type "partylist", ex:- "to"
I am able to retrieve them as an EntityCollection
Now i have to create another record and set the "to" field to the value retrieved in the step above
any suggestions?
Please have a look below code for the reference.
Apologies in advance for any syntax or build error, I have not tested it. But logic would be the same.
EntityCollection toCollection = (EntityCollection)sourcentityObj["to"];if (toCollection != null && toCollection.Entities.Count > 0){// get value of 'TO' field from source entity Entity toParty = toCollection[0]; //activityparty entityEntityReference toRef = (EntityReference)toParty["partyid"]; //actual entity ref // set value of 'TO' field in destination entityEntity partyListEntity= new Entity();
partyListEntity = new Entity("activityparty");
partyListEntity["partyid"] = toRef;
Entity[] aryTo = { partyListEntity};
partyListEntity["to"] = aryTo;}
EntityCollection Recipients = sourcentityObj.GetAttributeValue<EntityCollection>("to");
foreach (var party in Recipients.Entities) {
// get value of 'TO' field from source entityvar partyName = party.GetAttributeValue<EntityReference>("partyid").LogicalName;
var partyId = party.GetAttributeValue<EntityReference>("partyid").Id;
// set value of 'TO' field in destination entityEntity partyListEntity= new Entity();
partyListEntity["partyid"] = new EntityReference(partyName, partyId);
partyListEntity["to"] = aryTo;
}
If found useful, please mark the answer as verified.
CheersArpithttps://arpitmscrmhunt.blogspot.com
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
HR-09070029-0 2
ED-30091530-0 1