locked
populate partylist using javascript crm 2011 RRS feed

  • Question

  • HI,

    I'm using the following code to create entity using javascript. Everything works fine, but I need to populate one more field, 'required attendees' which is of type partylist and I can't get it right. Any suggestions on how to achieve that in my code?


    function CreateRecords(entitySet) {
        var serverUrl = Xrm.Page.context.getServerUrl().toString();
        var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
        var ODATA_EntityCollection = "/" + entitySet + 'Set';
    
        var objRecord = new Object();
      
    	var date = Xrm.Page.getAttribute("scheduledstart").getValue();
    	var type = Xrm.Page.getAttribute("new_type").getValue();
    	
    
        objRecord.RegardingObjectId = { Id: consId , LogicalName: "new_testentity", Name: consName };
    	objRecord.new_Type = {"Value": type };
    	objRecord.new_testentityId = { Id: consId , LogicalName: "new_testentity", Name: consName };
    	objRecord.new_Pe = { Id: peId , LogicalName: "systemuser", Name: peName };
    	objRecord.ScheduledStart = date;
    	
    	var jsonEntity = window.JSON.stringify(objRecord);
    
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection,
            data: jsonEntity,
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("Accept", "application/json");
            },
            success: function (response) {
                if (response != null && response.d != null) {
                  alert("success");
                }
            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
                alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);
            }
        });
    }
    

    SO I need to populate objRecord.RequiredAttendees and I tried to achieve this by using variations of the code block shown below

    var partyRequired = Xrm.Page.getAttribute("requiredattendees");
        var attendees = partyRequired.getValue();
          var partlistData = new Array(); 
    
        for (var i = 0; i < attendees.length; i++)
        {
        userId = attendees[i].id;
        userName = attendees[i].name;
         partlistData.push({
                id: userId,
                logicalName: userName,
                type: 'EntityReference'
            });
    
    }
    but I can't get it right. Any help will be appreciated.


    Tuesday, November 26, 2013 1:47 PM

All replies

  • Hello,

    As far as I know - this is the limitation of OData Endpoint. You just can't do it through OData. In case you want to create Appointment with attendees you will have to use SOAP endpoint.


    Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
    My blog

    Tuesday, November 26, 2013 3:42 PM
    Moderator