web
You’re offline. This is a read only version of the page.
close
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

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

I have the same question (0)
  • Verified answer
    Andreas Cieslik Profile Picture
    9,267 on at

    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;

    }

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    selectQuery looks fine.

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

    oDataResult = MakeRequest(selectQuery);

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans