If you observe “Required” lookup field on an ‘Appointment’ form, you can choose more than one Accounts or Contacts or Users.

Though it looks like a normal lookup field actually it’s a field of type ‘Party list’.

Party List :-

  • Party List is a data type in CRM, using which you can set more than one records of an entity for a single field.
  • Part List type field, renders as Lookup on the form, but it works as multi select lookup.
  • We can’t create a custom party list fields.

For example,

  • In the ‘Appointment’ entity field “Required” is a ‘Party List’ type
  • We can select multiple records of different type (i.e., Accounts, Users, Contacts…)
Partylist Type
Partylist Type

Below is Jscript to Get or Set ‘Partylist’

function getPartyList() {

var partyRequired = Xrm.Page.getAttribute(“requiredattendees”);

var attendees = party.getValue();

for (var indxAttendees = 0; indxAttendees < attendees.length; indxAttendees++) {

// User

if (attendees[indxAttendees].type == 8) {

alert(“Attendee is User; Id -” + attendees[indxAttendees].id + ” Name -” + attendees[indxAttendees].name);

}

// Contact

if (attendees[indxAttendees].type == 2) {

alert(“Attendee is Contact; Id -” + attendees[indxAttendees].id + ” Name -” + attendees[indxAttendees].name);

}

}

}

function setPartyList() {

var partyRequired = Xrm.Page.getAttribute(“requiredattendees”);

// Create new array

var partlist = new Array();

partlist[0] = new Object();

partlist[0].id = id; //Guid (i.e., Guid of User or Contact etc)

partlist[0].name = name; //Name (i.e., Name of User or Contact etc)

partlist[0].entityType = entityType; //entity schema name of account or contact

// Set array value

partyRequired.setValue(partlist);

}

Hope it helps 🙂

Advertisements
Advertisements

28 responses to “Get and Set ‘Partylist’ fields using Jscript”

  1. tirunesh@yahoo.com Avatar
    tirunesh@yahoo.com

    This looks very helpful Rajeev , what are the steps required to implement this code ? Please help

  2. John Avatar

    I use your way to set a value in phonecall entity “to” or recipient, it not working. I use CRM 2011 on premie, why? the followin is the code

    var o1 = new Array();
    o1[0] = new Object();
    o1[0].id = queryStringParams[“followup_3”] ;
    o1[0].name = queryStringParams[“followup_4”] ;
    o1[0].entityType = queryStringParams[“followup_5”] ;
    Xrm.Page.getAttribute(“to”).setValue(o1);

    1. Pramod ray Avatar
      Pramod ray

      how to set value in reqiredattendace field create appointment

  3. Rajeev Pentyala Avatar

    John,
    Please make sure you are setting right values using “queryStringParams”. Post the values you are passing and error text to find out cause of issue.

  4. mohsinkp Avatar

    hi Rajeev,
    I used your code set to field of email form.It sets the value.But when i click on the link it opens the create new record,even if the record exists.

    1. Rajeev Pentyala Avatar

      Hi,
      Did you set the 3 propeties
      partlist[0].id = id; //Guid
      partlist[0].name = name;
      partlist[0].entityType = entityType; //entity schema name

      Did the lookup resolve the party you set.
      Please provide your script to analyze more.

  5. mohsinkp Avatar

    Hi Rajeev,
    Thanks for your code it worked.
    I Used code below and it is working fine.
    var o1 = new Array();
    o1[0] = new Object();
    o1[0].id =fieldid;
    o1[0].name = tofieldname ;
    o1[0].entityType = ‘account’;
    Xrm.Page.getAttribute(“to”).setValue(o1);

  6. Selva Antony Avatar
    Selva Antony

    Hi Rajeev,

    Is there a way to make use of this party list field in any of our custom entity in crm 2011?
    If so please guide to proceed, that will be really really helpful for me.

    Thanks,
    Selva.

    1. Rajeev Pentyala Avatar

      Hi Selva,
      We cant create new PartyList field. However, you can create a new custom activity, with that you get out of the box PartyList fields.

  7. Selva Avatar
    Selva

    Hi Rajeev,

    I would like to make use of the partly list to Case entity. Is that possible to achieve?

    Thanks,
    Selva.

  8. progressinglife Avatar

    Hi Rajeev,
    Thanks for this great post. I would like to add a ressource to a service activity using soap endpoint, but I don’t seem to get it right …
    var CRMObject = new Object();
    var partlistData = new Array();
    partlistData[0] = new Object();
    partlistData[0].id = MyUser[0].id;
    partlistData[0].name = MyUser[0].name;
    partlistData[0].entityType = “SystemUser”;
    CRMObject.Resources = partlistData;
    What’s wrong with my configuration ?? thanks in advance

    1. Rajeev Pentyala Avatar

      Can you try by giving “SystemUser” lowercasing. (i.e., partlistData[0].entityType = “systemuser”).
      Let me know if you still face the issue.

  9. Pawa Joshi Avatar
    Pawa Joshi

    Xrm.Page.getAttribute(“to”).setValue(o1);
    in this syntax what is the “to”
    can anyone please help

    1. Rajeev Pentyala Avatar

      ‘to’ is the field name of Appointment entity.

  10. varun kumar Avatar

    Is there a way to set an Email for ex(abc@bbc.com) in the To value of the email

    1. Rajeev Pentyala Avatar

      No Varun.

      It considers the ‘Primary Email’ (I.e.,emailaddress1) field value of the Contact\User\Account .

  11. Sachin Avatar
    Sachin

    Hi Rajiv,

    I have a requirement when user create email activity from custom entity (contract) then in “To” field of email activity form, user can see the all the contacts associated to contract account (means account is parent of contract record) . So here i have to create one filtered custom view on Contact associated to Account. Can you help me , how to achieve this?

    1. Rajeev Pentyala Avatar

      Hi Sachin,
      Here is the article on how to filter lookup using JScript

      https://rajeevpentyala.wordpress.com/2013/06/17/filtering-lookup-view-based-on-custom-logic-crm-2011/

      Let me know if it doesn’t work for you.

  12. deepeshsomani2013 Avatar

    Reblogged this on Dynamicsofdynamicscrm and commented:
    This was a recent query asked to me. Adding a solution done by my old colleague Rajeev here:

  13. […] Originally posted on Rajeev Pentyala – Dynamics CRM Blog: […]

  14. […] is some scripting you can implement – based on Rajeev Pentyala’s blog based here: https://rajeevpentyala.wordpress.com/2012/04/02/get-and-set-partylist-fields-using-jscript/ It’s tricky to work this out since there are Activity Parties / Party Lists […]

  15. Sunil R Avatar
    Sunil R

    Thanks a lot for this blog. It really helped solve my purpose.

  16. Rajesh Avatar
    Rajesh

    For me the images are not displaying on booth the partylist however, data are swaping and setting entity attribute correctly. Could you please help me

  17. Avik Banerjee Avatar
    Avik Banerjee

    The following alteration worked for setting email’s to attribute in CRM 2015, the only change is object’s type is to be set and not entitytype.
    var partlistData = new Array();
    partlistData[0] = new Object();
    partlistData[0].id = Xrm.Page.context.getUserId();
    partlistData[0].name = Xrm.Page.context.getUserName();
    partlistData[0].type = 8;
    Xrm.Page.getAttribute(“to”).setValue(partlistData);

    Appreciate your blogs, Rajiv!

  18. Tri Avatar
    Tri

    Hi Rajeev,
    Thanks for posting this useful blog.
    I’m trying to insert multiple participants into the email “to” field when users click on “Reply All” email. However I need to remove certain email address from the To line. So I put the original To into an array and then loop and get all the email addresses except the one that needs to be removed.

    However the problem here is I only see the first participant is listed on the Reply All email form. Could you please advise on how to populate multiple email participants? Appreciate your help in this, thanks in advance.

    Here’s my code:
    var toParty = Xrm.Page.getAttribute(“to”).getValue();

    var partyListArray = new Array();
    for (var indxAttendees = 0; indxAttendees < toParty.length; indxAttendees++) {
    //using oData to get participant email address
    var email = getParticipantEmail(toParty[indxAttendees].entityType, toParty[indxAttendees].id);
    if (email != "test@test.com") {
    partyListArray[indxAttendees] = new Object();
    partyListArray[indxAttendees].id = toParty[indxAttendees].id;
    partyListArray[indxAttendees].name = toParty[indxAttendees].name;
    partyListArray[indxAttendees].entityType = toParty[indxAttendees].entityType;
    }
    }

    Xrm.Page.getAttribute("to").setValue(null);
    Xrm.Page.getAttribute("to").setValue(partyListArray);

  19. Raghu Nandan Avatar
    Raghu Nandan

    Hi Rajeev,

    I have the following problem:

    When I enter values in “Required” field in Appointment and then while converting the appointment to Case the pop-up auto populates the “Customer” value with the “Required” value in appointment. That is working fine.
    But when I do the same for a custom activity, then the “Customer” field is not getting populated with the “Required” filed value on custom activity.

    Is that the expected behavior for a custom activity or we need to do anything else ?

    Thanks,

  20. Jyoti Nandakr Avatar
    Jyoti Nandakr

    hello rajeev can we use this code

    crmForm.all.requiredattendees.setAttribute(“defaulttype”, “2”);

    crmForm.all.requiredattendees.setAttribute(“lookuptypes”, “2”);

    crmForm.all.requiredattendees.setAttribute(“lookuptypeIcons”, “/_imgs/ico_16_2.gif”);

    to disable one of the entity from party list in CRM 2016

Leave a reply to Rajesh Cancel reply