locked
Getting/Setting OwnerId in javascript RRS feed

  • Question

  • Hello All,

    I'm trying to set a lookup value on a form based on a previous lookup. I didn't find an example that fit my case, so i'm hoping someone here can help show me what I'm doing wrong.

    // Get the ID of my child object
    var Id = Xrm.Page.getAttribute("regardingobjectid").getValue()[0].id.replace("{", "").replace("}", "");
    
    // Set up the filter to get the related contact
    var filter = "?$select=OwnerId,EMailAddress1,EMailAddress2&$filter=ContactId eq (guid'" + Id + "')";
    
    // function to retrieve the related entity
    var contact = MyNS.MyEntity.retrieveRecord("ContactSet", filter); 
    
    // Update some form fields. These work OK.
    if (!isNullOrEmptyString(contact.results[0].EMailAddress1))
        Xrm.Page.getAttribute("seiu_homeemailaddress").setValue(contact.results[0].EMailAddress1);
    
    if (!isNullOrEmptyString(contact.results[0].EMailAddress2))                        
        Xrm.Page.getAttribute("seiu_workemailaddress").setValue(contact.results[0].EMailAddress2);
    
    // Here contact.results[0] is NOT null, but I am not able to get the GUID value to construct the filter string ...
    var filter = "?$select=SystemUserId,FirstName,LastName&$filter=SystemUserId/Id eq (guid'" + contact.results[0].OwnerId.id + "')";
    // ... consequently, this call fails.
    var oOwner = MyNS.MyEntity.retrieveRecord("SystemUserSet", filter);
    

    Is there any reason why OwnerId isn't returning from the first call? I'm hoping I'm missing something simple.

    Thanks,

    -tomas

    Monday, February 27, 2012 11:44 PM

All replies