Get and Set ‘Partylist’ fields using Jscript
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…)
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 🙂
This looks very helpful Rajeev , what are the steps required to implement this code ? Please help
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);
how to set value in reqiredattendace field create appointment
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.
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.
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.
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);
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.
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.
Hi Rajeev,
I would like to make use of the partly list to Case entity. Is that possible to achieve?
Thanks,
Selva.
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
Can you try by giving “SystemUser” lowercasing. (i.e., partlistData[0].entityType = “systemuser”).
Let me know if you still face the issue.
Xrm.Page.getAttribute(“to”).setValue(o1);
in this syntax what is the “to”
can anyone please help
‘to’ is the field name of Appointment entity.
Is there a way to set an Email for ex(abc@bbc.com) in the To value of the email
No Varun.
It considers the ‘Primary Email’ (I.e.,emailaddress1) field value of the Contact\User\Account .
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?
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.
Reblogged this on Dynamicsofdynamicscrm and commented:
This was a recent query asked to me. Adding a solution done by my old colleague Rajeev here:
Thanks a lot for this blog. It really helped solve my purpose.
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
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!
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);
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,
Hi, I have added this Java Script in form properties and On change event of “Required attendees” field. But it gives below error.
ReferenceError: getPartyList is not defined
at eval (eval at RunHandlerInternal (https://hisysmcuat.crm5.dynamics.com/form/ClientApiWrapper.aspx?ver=878391262:153:1), :1:1)
at RunHandlerInternal (https://hisysmcuat.crm5.dynamics.com/form/ClientApiWrapper.aspx?ver=878391262:157:1)
at RunHandlers (https://hisysmcuat.crm5.dynamics.com/form/ClientApiWrapper.aspx?ver=878391262:116:1)
at ExecuteHandler (https://hisysmcuat.crm5.dynamics.com/form/ClientApiWrapper.aspx?ver=878391262:79:1)
at Mscrm.TurboForm.Control.CustomScriptsManager.$Cb_1 (https://hisysmcuat.crm5.dynamics.com/_static/form/formcontrols.js?ver=878391262:3342:100)
at Mscrm.TurboForm.Control.CustomScriptsManager.executeHandler (https://hisysmcuat.crm5.dynamics.com/_static/form/formcontrols.js?ver=878391262:3288:18)
at Mscrm.TurboForm.Control.CustomScriptsManager.executeHandlerByDescriptor (https://hisysmcuat.crm5.dynamics.com/_static/form/formcontrols.js?ver=878391262:3319:18)
at https://hisysmcuat.crm5.dynamics.com/_static/form/formcontrols.js?ver=878391262:3327:19
at https://hisysmcuat.crm5.dynamics.com/_common/global.ashx?ver=878391262:4024:149483
at Mscrm.TurboForm.Control.Data.DataEntity.$De_1 (https://hisysmcuat.crm5.dynamics.com/_static/form/formcontrols.js?ver=878391262:13185:13):1:1)
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