locked
who am I RRS feed

  • Question

  • The listing of the form attributes include nothing about the user.  Do I have to set up a whoamI message to know anything about the user or is there an object already "in session" that I can access?  I'm looking for business unit specifically.
    Friday, April 17, 2009 2:30 PM

Answers

  • Hi mardukes,

    sorry, there is no simple method for finding that out.

    But in this article written by Michael from stunnware you can get an appropriate JScript to find out everything about the current user:
    http://www.stunnware.com/crm2/topic.aspx?id=js31

    Best regards,
    Jürgen
    Jürgen Beck

    Dipl. Kfm./Wirtschaftsinformatik
    MVP, MCSD.NET, MCITP DBA, MCDBA, MCSE
    Microsoft Certified Business Management Solutions Professional
    Microsoft Certified CRM Developer
    Microsoft Certified Trainer

    ComBeck IT Services & Business Solutions
    Microsoft Gold Certified Partner
    Microsoft Small Business Specialist

    Developing & Supporting Business Applications from small business to big enterprises covering scores of sectors

    http://www.combeck.de
    Friday, April 17, 2009 8:08 PM
    Moderator

All replies

  • Hi mardukes,

    sorry, there is no simple method for finding that out.

    But in this article written by Michael from stunnware you can get an appropriate JScript to find out everything about the current user:
    http://www.stunnware.com/crm2/topic.aspx?id=js31

    Best regards,
    Jürgen
    Jürgen Beck

    Dipl. Kfm./Wirtschaftsinformatik
    MVP, MCSD.NET, MCITP DBA, MCDBA, MCSE
    Microsoft Certified Business Management Solutions Professional
    Microsoft Certified CRM Developer
    Microsoft Certified Trainer

    ComBeck IT Services & Business Solutions
    Microsoft Gold Certified Partner
    Microsoft Small Business Specialist

    Developing & Supporting Business Applications from small business to big enterprises covering scores of sectors

    http://www.combeck.de
    Friday, April 17, 2009 8:08 PM
    Moderator
  • Mardukes -

    Take a look at Michael's example (in Jurgen's post) - Michael's example includes the business unit id along with the name and organization ids.

    Scott
    Scott Sewell, CustomerEffective | http:\\blog.CustomerEffective.com | Twitter:@ScottSewell
    Friday, April 17, 2009 8:18 PM
    Moderator
  • Here's my contribution to the subject (though I will be returning the results rather than the string):

    function getWhoBeMe() {
    /********************************************************************************
    *  gather information about the current user
    *
    */
    
        var authenticationHeader = GenerateAuthenticationHeader();
    
      //Prepare the SOAP message.
        var xml = "<?xml version='1.0' encoding='utf-8'?>"
        +"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"
        +"  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
        +"  xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"
        + authenticationHeader
        +"<soap:Body>"
        +"<Fetch xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"
        +"<fetchXml>"
        + "&lt;fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'&gt;"
        + "  &lt;entity name='role'&gt;"
        + "    &lt;attribute name='name'/&gt;"
        + "    &lt;attribute name='businessunitid'/&gt;"
        + "    &lt;attribute name='roleid'/&gt;"
        + "    &lt;order attribute='name' descending='false'/&gt;"
        + "    &lt;link-entity name='systemuserroles' from='roleid' to='roleid' visible='false' intersect='true'&gt;"
        + "      &lt;link-entity name='systemuser' from='systemuserid' to='systemuserid' alias='aa'&gt;"
        + "        &lt;attribute name='systemuserid'/&gt;"
        + "        &lt;attribute name='fullname'/&gt;"
        + "        &lt;filter type='and'&gt;"
        + "          &lt;condition attribute='systemuserid' operator='eq-userid'/&gt;"
        + "        &lt;/filter&gt;"
        + "      &lt;/link-entity&gt;"
        + "    &lt;/link-entity&gt;"
        + "  &lt;/entity&gt;"
        + "&lt;/fetch&gt;"
        +"</fetchXml>"
        +"</Fetch>"
        +"</soap:Body>"
        +"</soap:Envelope>";
    
       //Prepare the xmlHttpObject and send the request.
       var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
       xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
       xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
       xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
       xHReq.setRequestHeader("Content-Length", xml.length);
       xHReq.send(xml);
    
       //Capture the result
       var resultXml = xHReq.responseXML;
    
       //Check for errors.
       var errorCount = resultXml.selectNodes('//error').length;
       if (errorCount != 0)
       {
          var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
          alert(msg);
       }
       //Process and display the results.
       else
       {
        //Capture the result and UnEncode it.
          var resultSet = new String();
          resultSet = resultXml.text;
          resultSet.replace('&lt;','<');
          resultSet.replace('&gt;','>');
    
        // Create an XML document that you can parse.
          var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
          oXmlDoc.async = false; 
    
        // Load the XML document that has the UnEncoded results.
          oXmlDoc.loadXML(resultSet);
    alert(oXmlDoc.xml);
    
        //Display the results.
          var results = oXmlDoc.getElementsByTagName('result');
          var name = results[0].selectSingleNode('./aa.fullname').nodeTypedValue;
          var buname= results[0].selectSingleNode('./businessunitid').getAttribute('name');
          var businessunitid= results[0].selectSingleNode('./businessunitid').nodeTypedValue;
          var systemuserid= results[0].selectSingleNode('./aa.systemuserid').nodeTypedValue;
          var msg = "user:\t"+ name + "\nuserid:\t" + systemuserid + "\nbuid:\t" + businessunitid + "\nbu:\t" + buname;
          for (var i=0; i<results.length; i++) msg += "\n" + i + ":\trole:\t"+ results[i].selectSingleNode('./name').nodeTypedValue;
    
          return msg;
       }
    }
    //End Of function
    
    alert(getWhoBeMe());
    Tuesday, April 21, 2009 9:18 PM