Advertisements

Archive

Posts Tagged ‘Partylist’

Filtering partylist entities using jscript in CRM

August 2, 2012 5 comments

In CRM, partylist Party List is a data type, using which you can set more than one type of entity records for a single field

For example,

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

In one of my requirement, I have to restrict the party list field to show only ‘Contacts’. (i.e., I can only choose Contacts)

We can achieve by setting below properties to partylist field using jscript

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

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

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

Here ‘2’ is the Entity Type Code of ‘Contact’ entity

After setting the properties, the partylist look as below with ‘Contact’ chosen as default and in disabled state to restrict other entity selction

Filtered Party List

Filtered Party List

In case you have to filter 2 entities, let’s say Contact & User you have to set “lookuptypes & lookuptypenames & lookuptypeIcons” properties

            lookuptypeIcons = ‘/_imgs/ico_16_2.gif:/_imgs/ico_16_8.gif’;

lookuptypenames = ‘contact:2:Contact,systemuser:8:User’;

lookuptypes = ‘2,8’;

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

crmForm.all.requiredattendees.setAttribute(“lookuptypenames”, lookuptypenames);

crmForm.all.requiredattendees.setAttribute(“lookuptypeIcons”, lookuptypeIcons);

🙂

Advertisements

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…)
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 🙂