Party List Fields in Dynamics 365

In Dynamics 365, an activity (phonecall, task, email, appointment) can either be associated with a single person or a group of person which represent the Activity Party. An activity can have multiple activity parties.

For Example, an email can either be sent to CRM Contacts or CRM User or Queue. So there must be such type of field available in CRM which can refer to multiple entities as Lookup can only be associated to only single entity. Hence Party List comes into picture.

When you add any Party List type of field on the CRM form, you may notice that these fields look like Lookup fields but may function a little different. For example the Email\’s From and To fields let you select multiple records of the same or different type.

  • CRM Activity Party List field is a special type of lookup field which refers to multiple entities. To hold or store these multiple entities references, Microsoft has provided one special type of entity named Activity Party.
  • Activity Party, has one special field called Party Id. which has the capability to store multiple entities references like user, contact, account, lead etc.
  • Hence, if we have to get/set value in Party List Field, we have to interact with Activity Party Party Id field.
  • So, we just have to remember, while getting or setting value in party list fields (to, from cc, bcc, regarding etc). We have to use Activity Party Entity and Party Id field. We can understand it better through code also.

Get value from Party List Fields using C#

public static void Main(string[] args)
{
  // Pass the email record guid
getPartyList(
\"C4723A9F-592F-E911-A979-000D3AF24324\");
}
public static void getPartyList(string emailRecordId)
{

// Retrieve email record
//Here service is your IOrganisation Service Object
Entity email = 
service.Retrieve(\"email\",new Guid(emailRecordId),new ColumnSet(\"from\", \"to\"));


// get value from partylist - \'FROM\' field

EntityCollection from = email.GetAttributeValue<EntityCollection>(\"from\"); if (from != null && from.Entities.Count > 0) { foreach (var item in from.Entities) {

  EntityReference partyId = item.GetAttributeValue<EntityReference>(\"partyid\");

string addressUsed = item.GetAttributeValue<string>(\"addressused\");

Console.WriteLine(\"Email Send From: \" + partyId.Name + \",\" + addressUsed);

}
 }

Console.WriteLine(\"------------------------------------------------------------------\");

// get value from partylist - \'TO\' field

EntityCollection to = email.GetAttributeValue<EntityCollection>(\"to\"); if (to != null && to.Entities.Count > 0) { foreach (var item in to.Entities) { EntityReference partyId = item.GetAttributeValue<EntityReference>(\"partyid\"); string addressUsed = item.GetAttributeValue<string>(\"addressused\"); Console.WriteLine(\"Email Send To: \" + partyId.Name + \",\" + addressUsed); } } Console.ReadKey();


}

Output


Set value in Party List Fields using C# (Single Recipient)

public static void Main(string[] args)
{
  // call the function in Main

SetPartyList_SingleRecipient();

}

public static void SetPartyList_SingleRecipient()
{
// declare party list entity to set value in FROM field
Entity from = new Entity(\"activityparty\");
// declare party list entity to set value in TO field
Entity to = new Entity(\"activityparty\");

// set value in FROM field
from[\"partyid\"] =
new EntityReference(\"systemuser\", new Guid(\"D72D8D9E-FCEC-4C6B-8340-A2CB9FAA88D5\"));

// set value in TO field
to[
\"partyid\"] =
new EntityReference(\"account\", new Guid(\"475B158C-541C-E511-80D3-3863BB347BA8\"));

// declare party list entity to set value in FROM field
Entity email = new Entity(\"email\");

// insert value in email FROM field
email[\"from\"] = new Entity[] { from };
// insert value in email TO field
email[\"to\"] = new Entity[] { to };

//Set regarding object property (i.e. The entity record, which u want this email associated with)
EntityReference regardingObject =
new EntityReference(\"contact\", new Guid(\"49A0E5B9-88DF-E311-B8E5-6C3BE5A8B200\"));
  email.Attributes.Add(\"regardingobjectid\", regardingObject);

//Set subject & body properties
email.Attributes.Add(\"subject\", \"Email created from Console for Single recipients\");
email.Attributes.Add(\"description\", \"Email created from Console for Single recipients\");

//Create email activity
  //Here service is your IOrganisation Service Object

Guid emailID = service.Create(email); Console.WriteLine(\"Email created successfully\"); Console.Read();

}


Output
























Set value in Party List Fields using C# (Multiple Recipient)

public static void Main(string[] args)
{
  // call the function in Main

SetPartyList_MutipleRecipient();

}

public static void SetPartyList_MutipleRecipient()
{
// set value in FROM party list field
Entity from1 = new Entity(\"activityparty\");

// two accounts inside the TO field
Entity to1 = new Entity(\"activityparty\");
Entity to2 = new Entity(\"activityparty\");
// two contacts inside the TO field
Entity to3 = new Entity(\"activityparty\");
Entity to4 = new Entity(\"activityparty\");

// set value in FROM field
from1[
\"partyid\"] =
new EntityReference(\"systemuser\", new Guid(\"D72D8D9E-FCEC-4C6B-8340-A2CB9FAA88D5\"));

// set multiple values in TO field
to1[
\"partyid\"] =
new EntityReference(\"account\", new Guid(\"475B158C-541C-E511-80D3-3863BB347BA8\"));
to2[
\"partyid\"] =
new EntityReference(\"account\", new Guid(\"A8A19CDD-88DF-E311-B8E5-6C3BE5A8B200\"));
to3[
\"partyid\"] =
new EntityReference(\"contact\", new Guid(\"25A17064-1AE7-E611-80F4-E0071B661F01\"));
to4[
\"partyid\"] =
new EntityReference(\"contact\", new Guid(\"49A0E5B9-88DF-E311-B8E5-6C3BE5A8B200\"));
 Entity email = new Entity(\"email\");

//Set regarding object property (i.e. The entity record, which u want this email associated with)
EntityReference regardingObject =
new EntityReference(\"contact\", new Guid(\"49A0E5B9-88DF-E311-B8E5-6C3BE5A8B200\"));

email.Attributes.Add(\"regardingobjectid\", regardingObject);

// Insert value in FROM field
email[\"from\"] = new Entity[] { from1 };
// Insert value in TO field
email[\"to\"] = new Entity[] { to1, to2, to3, to4 };

//Set subject & body properties
email.Attributes.Add(\"subject\", \"Email created from Console for Multiple recipients\");
email.Attributes.Add(\"description\", \"Email created from Console or Multiple recipients\");

//Create email activity
   //Here service is your IOrganisation Service Object

Guid emailID = service.Create(email); Console.WriteLine(\"Email created successfully\"); Console.Read();

}

Output














In the above code,

To get the value from Party List TO and FROM fields:

We are retrieving the value from Party Id field of Activity Party entity, which holds the record’s Guids which was selected in Email’s FROM and TO fields.
To set the value in Party List TO and FROM fields:

We are first passing the value in Party Id field of Activity Party entity and then setting it’s Entity reference to partylist FROM and TO fields.


Note: 

  • For demonstration, I have hard-coded the record Guids. However, in real time you\’ll have to pick these values dynamically based upon your requirement.
  • For demonstration, I have taken the example of Email Activity Entity and it\’s To and From party list fields. Same code/logic can also be used for other activities and party list fields.
Thanks for your time. Please do share your valuable feedback. It means a lot for me.

Cheers

Published by arpitpowerguide

My name is Arpit Shrivastava, who is a Microsoft MVP in the Business Applications category. I am a Microsoft Dynamics 365 and Power Platform enthusiast person who is having a passion for researching and learning new things and acquiring immense knowledge. I am providing consistent help, support, and sharing my knowledge through various Social Media Channels along with my Personal Blog, Microsoft Community, conducting online training and attending various 365 Saturday Events worldwide and sharing the best Solutions to the readers helping them achieve their goals and objectives in Customer Relationship Space.

42 thoughts on “Party List Fields in Dynamics 365

  1. Very nice site. I came across this on Google, and I am stoked that I did. I will definitely be coming back here more often. Wish I could add to the conversation and bring a bit more to the table, but am just taking in as much info as I can at the moment. I am an CRM developer, I recently work on web based CRM software. Thanks for sharing such great content.

    Like

  2. Hello, Thank you for this excellently put together blog. It is very clear and helpful.How do you update an existing From field on email? The reason is I'm working on a case management solution in CRM and I've got the case creation rules set to not create a contact for emails where the contact does not already exist.For emails from unknown sources I'd like to be able to run a dialog on selected emails and 'escalate them to contact+case'. This will create a contact with the email field being taken from the sender's email and then my dialog creates a case and sets the regarding field on the original email to be the new case.This is all good except the 'From' field on the original email is still showing as 'unresolved' id.e. the address used is still showing the email in red in the from field and not the newly created contact. I'm trying to write a plugin which sets the from field to the newly created contact but it's not updating.Do I need to create a new email and delete the old email or can I update the old email's from field?Thank you,Mohamed

    Like

  3. Great blog learned many things about Crm Software from this article, very informative .CRM system is the software that you and your company need to automate the processes and activities associated with customer relationship management. For many years, the locally hosted CRM solutions have widely been used by large corporations and medium-sized businesses. Today, you have a chance to implement the CRM systems, too. Likewise, you have a possibility to choose between the locally hosted and web based CRM solutions. The only way to make the right choice is to learn more about the different types of CRM systems.Best Crm Software for Small Businesscrm systems for small businessesbest business management softwareClient Management Software for Small Business Customer Relation Management Software Customer Management Software Small Business Dropshipping Software

    Like

  4. Hello there! This is my first comment here, so I just wanted to give a quick shout out and say I genuinely enjoy reading your articles. Can you recommend any other blogs/websites/forums that deal with the same subjects? Thanks.Surya Informatics

    Like

  5. Thank you for this excellently put together blog. It is very clear and helpful. If you are in a business and want to get a highly professional and effective customer relationship management solution to make a strong client base there are a number of expert services whom you can look up to get the best solutions. Choose them wisely and get the best benefits of this best business management software system with their help.crm systems for small businesses|Client Management Software For Small Business|Customer Relation Management Software

    Like

  6. Good articles, Have you heard of LFDS (Le_Meridian Funding Service, Email: lfdsloans@outlook.com –WhatsApp Contact:+1-9893943740–lfdsloans@lemeridianfds.com) is as USA/UK funding service they grant me loan of $95,000.00 to launch my business and I have been paying them annually for two years now and I still have 2 years left although I enjoy working with them because they are genuine Loan lender who can give you any kind of loan.

    Like

  7. Special thanks to (hackingsetting50@gmail.com) for exposing my cheating husband. Right with me i got a lot of evidences and proofs that shows that my husband is a fuck boy and as well a cheater ranging from his text messages, call logs, whats-app messages, deleted messages and many more, All thanks to (hackingsetting50@gmail.com), if not for him i will never know what has been going on for a long time. Contact him now and thank me later.

    Like

Leave a comment