locked
How to identify if Contact owner is a User or a Team RRS feed

  • Question

  • In our system (CRM 2011) a Contact may be owned by a User or by a Team. I need to identify in jscript which of the two it is, for a given Contact.

    How can I do that?


    • Edited by MeProgrammer Friday, August 3, 2012 3:39 PM add detail
    Friday, August 3, 2012 3:12 PM

Answers

  • Please see this. See the properties available for the lookup type. See if recordOwner.getValue()[0].entityType gives you 'systemuser' or 'team'.

    • Proposed as answer by MayankAgrawal Friday, August 3, 2012 8:17 PM
    • Marked as answer by MeProgrammer Sunday, August 5, 2012 1:35 AM
    Friday, August 3, 2012 8:17 PM
  • This this out:

    function GetType() {
        var retrieveReq = new XMLHttpRequest();
        var ODataPath = Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc/ContactSet?$select=OwnerId&$filter=ContactId eq guid'" + Xrm.Page.data.entity.getId() + "'";
    
        retrieveReq.open("GET", ODataPath, true);
        retrieveReq.setRequestHeader("Accept", "application/json");
        retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        retrieveReq.onreadystatechange = function () {
            retrieveReqCallBack(this);
        };
        retrieveReq.send();
    }
    
    function retrieveReqCallBack(retrieveReq) {
        if (retrieveReq.readyState == 4) {
            if (retrieveReq.status == 200) {
                var retrieved = JSON.parse(retrieveReq.responseText).d;
                var type = retrieved.results[0].OwnerId.LogicalName;
                alert(type);
            } else {
                //error
            }
        }
    }
    

    Jason Lattimer

    Saturday, August 4, 2012 3:20 AM
    Moderator

All replies

  • [I posted this question to the CRM Development forum but as nobody's responded, I thought I'd try here. Sorry for the duplicate posting.]

    Is is possible, using jscript, to determine whether the Owner of a Contact is a User or a Team?

    I have:

    var ODataPath = ServerURL + "/XRMServices/2011/OrganizationData.svc";
    
         retrieveRecordsReq.open('GET', ODataPath + "/SystemUserSet?$select=DomainName&$filter=SystemUserId eq guid'" +    recordOwner.getValue()[0].id + "'", false);
         retrieveRecordsReq.setRequestHeader("Accept", "application/json");
         retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
         retrieveRecordsReq.send();
    
         var records = this.parent.JSON.parse(retrieveRecordsReq.responseText).d;
         TmpUser = records.results[0].DomainName;

    But this is throwing an error if the Owner is a Team because Domain Name is not an attribute on the Team entity.

    So I need to either identify up front whether or not the Owner is a Team, or determine whether or not DomainName is in the records.results[0] collection before trying to retrieve it.

    Can someone assist?  Thank you.

    Friday, August 3, 2012 6:45 PM
  • Please see this. See the properties available for the lookup type. See if recordOwner.getValue()[0].entityType gives you 'systemuser' or 'team'.

    • Proposed as answer by MayankAgrawal Friday, August 3, 2012 8:17 PM
    • Marked as answer by MeProgrammer Sunday, August 5, 2012 1:35 AM
    Friday, August 3, 2012 8:17 PM
  • This this out:

    function GetType() {
        var retrieveReq = new XMLHttpRequest();
        var ODataPath = Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc/ContactSet?$select=OwnerId&$filter=ContactId eq guid'" + Xrm.Page.data.entity.getId() + "'";
    
        retrieveReq.open("GET", ODataPath, true);
        retrieveReq.setRequestHeader("Accept", "application/json");
        retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        retrieveReq.onreadystatechange = function () {
            retrieveReqCallBack(this);
        };
        retrieveReq.send();
    }
    
    function retrieveReqCallBack(retrieveReq) {
        if (retrieveReq.readyState == 4) {
            if (retrieveReq.status == 200) {
                var retrieved = JSON.parse(retrieveReq.responseText).d;
                var type = retrieved.results[0].OwnerId.LogicalName;
                alert(type);
            } else {
                //error
            }
        }
    }
    

    Jason Lattimer

    Saturday, August 4, 2012 3:20 AM
    Moderator
  • Thank you, Mayank!
    Sunday, August 5, 2012 1:33 AM
  • Thank you, Jason!
    Sunday, August 5, 2012 1:33 AM