Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

alert box displaying user name and title

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

hello everyone~

i am currently working on a project where i was giving a pretty straight forward requirement. 

depending on the user display certain things. i figured i would just write some JS and implement it via a web resource to grab the user and then query their title. if the title of the user equals a then display a, if b display b. my problem is i cant get my code to work. my code is below, can anyone point me in the right direction to fix my error. i believe my error is in the var selectquery line, but i am not sure where

function MakeRequest(query) {

    var lookupObject = Xrm.Page.getAttribute("ownerid");
    if (lookupObject != null) {
        var lookUpObjectValue = lookupObject.getValue();
        if ((lookUpObjectValue != null)) {
            var lookupid = lookUpObjectValue[0].id;
        } 
    } 
    var selectQuery = "/SystemUserSet?&$filter=SystemUserId eq guid'" + lookupid + "'&$select=JobTitle, FullName";
    var oDataResult = null;
    oDataResult = MakeRequest(selectQuery);
    alert("Name = " + oDataResult[0].FullName + "\n" + "Job Title = " + oDataResult[0].JobTitle);

*This post is locked for comments

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,401 on at
    RE: alert box displaying user name and title

    Hi

    selectQuery looks fine.

    Is this the full code? Why you are calling the same function within the function (recursively).

    oDataResult = MakeRequest(selectQuery);

  • Verified answer
    Andreas Cieslik Profile Picture
    Andreas Cieslik 9,267 on at
    RE: alert box displaying user name and title

    Hi,

    this should work (from Chitrarasan Duraisamy taken from this post https://community.dynamics.com/crm/f/117/t/155839 :

    function getUserInfo() {

       var req = new XMLHttpRequest();

       req.open("GET", encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/SystemUserSet(guid'" + Xrm.Page.context.getUserId() + "')?$select=FullName,Title"), false);

       req.setRequestHeader("Accept", "application/json");

       req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

       req.send();

       var result = JSON.parse(req.responseText).d;

       if (result.FullName !=null)

       var FullName = result.FullName;

       if (result.Title != null)

       var Title = result.Title;

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans