How to set a partylist with javascript

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.
  • Party 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.

Function to set  Call To in a Phone Call Activity (tested on CRM 2015 Update 1 Online):

function setCallTo() {
    debugger;
    var callTo = getAttr("to"); //Party list to set

    var callToArry = new Array(); 
    callToArry[0] = new Object(); 

    callToArry[0].id = getLkpId("new_calltocontact");
    callToArry[0].name = getLkpName("new_calltocontact");
    callToArry[0].entityType = "contact";

    callTo.setValue(callToArry);
}
function getAttr(attributeId) {
    return Xrm.Page.getAttribute(attributeId);
}
function getVal(attributeId) {
    try {
        return Xrm.Page.getAttribute(attributeId).getValue();
    }
    catch (e) {
        alert("getVal: Error for attribute " + attributeId);
    }
}
function getLkpName(attributeId) {
    return getVal(attributeId)[0].name;
}
function getLkpId(attributeId) {
    return getVal(attributeId)[0].id;
}