1
votes

We are currently using Dynamics CRM 2016. We have an iframe which will be used to load another application for the time being. We would like to pass into the URL of the iframe the username of the account currently logged into CRM. With the below js function I'm able to get the UserId and Name, but it's the Full Name, not the username on the account:

    function createUrl() {
  //var user = Xrm.Page.context.getUserId(); 
  var user = Xrm.Page.context.getUserName(); 
  var url = "http://myapp/app?user=" + user;
  Xrm.Page.getControl('IFRAME_externalSite').setSrc(url);
}

the only solution I could find was to use the UserId from the Xrm.Page.context.getUserId() method and query the SystemUser Entities through OData and retrieve the username from there. Is there another way without querying the OData service?

1

1 Answers

6
votes

No, you must query the SystemUser entity if you want to get additional fields of the logged user other than the ones available with the getUserId and getUserName methods.

Keep in mind that if you are using CRM 2016, you should start to use the new WebAPI (oData 4.0) and not the old oData 2.0 endpoint