Wednesday, 13 February 2019

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

28 comments:

  1. Hi Arpit,

    Can you please elaborate more about the 'From' field in your next post, as it has few restriction compared to other partylist type fields.

    Thanks,
    Amit Kumar Rath

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Mohamed Ismail3 July 2019 at 10:02

    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

    ReplyDelete
  4. Nice Article.
    We are Software Solution Providers in Islamabad, working with international clients in creating, designing and managing their websites and customer relations/Sales etc.
    We Provide:
    1.) SEO and Digital Marketing Services
    2.) Web Design and Development Services
    3.) CRM and ERP systems

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. Very informative blog about CRM. Thanks for enhancing our knowledge about CRM. Are you looking to improve customer satisfaction levels through our Microsoft Dynamics CRM? Talk to our CRM experts to know what features you can use to make your CRM process more efficient and ultimately boost your productivity.

    ReplyDelete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete
  12. Thanks for sharing an informative post, If you wants to know about CRM system This is the right place for you.

    ReplyDelete
  13. It’s a wonderful blog you shared here, I read the whole content and found it so easy to understand in language and is also full of amazing and useful information. Thanks a lot for sharing it.Restaurant Online Ordering app

    ReplyDelete
  14. This was actually what i was looking for,and i am glad to came here you keep up the fantastic work!my weblog.. I like the trend that content is becoming more and more important.
    CRM Software In India
    CRM Software In Chennai
    CRM Software In Bangalore

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. This comment has been removed by a blog administrator.

    ReplyDelete
  17. This comment has been removed by a blog administrator.

    ReplyDelete
  18. This comment has been removed by a blog administrator.

    ReplyDelete
  19. This comment has been removed by a blog administrator.

    ReplyDelete
  20. Really appreciate you sharing this article post. Happy Valentines Day Much thanks again. Awesome.

    ReplyDelete
  21. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.
    Best CRM System

    ReplyDelete
  22. Im no expert, but I believe you just made an excellent point. You certainly fully understand what youre speaking about, and I can truly get behind that. Shisha Hire London

    ReplyDelete
  23. Why do only so much written on this subject? Here you see more. Shisha Hire

    ReplyDelete
  24. This is most informative and also this post most user-friendly and super navigation to all posts.
    3d Laser Scanning Services in Birmingham
    Dimension Control services in Bayern Germany

    ReplyDelete
  25. 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.

    ReplyDelete
  26. How do I set an email address to a to field as party list. The email address is unresolved and respective contact doesn't exist.

    ReplyDelete

Blogger Widgets