web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get the Logged in user location (country) in javascript code

(0) ShareShare
ReportReport
Posted on by 30

I have one requirement to implement which is, based on Logged In User's location (get country name) I have to set the currency in opportunity creation in D365, Please share your idea and thoughts how can it be achievable ?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    Hi Ankit,

    You have to use wep api request to achieve this. create the JS and call the function on onload of the form or any other event.

    here is how you get the logged in user id =

    var userSettings = Xrm.Utility.getGlobalContext().userSettings; // userSettings is an object with user information. var current_User_Id = userSettings.userId; // The user's unique id var newid = current_User_Id.slice(1, -1);

    Then use rest builder to generate a request to get above user's location:
    https://github.com/jlattimer/CRMRESTBuilder/releases - download and install this tool
    - it will help to generate web api requests.


    0358.2.png


    0358.2.png

  • Ankit S Profile Picture
    30 on at

    Thanks for Reply, here my query is different, I can get the user setting's territoryid using webapi query in javascript. but I want logged-in user's machine's location (country) based on that I want to set currency while creating Opportunity.

  • Suggested answer
    BadrinathB Profile Picture
    970 on at

    Hi,

    If you want to get location using mobile devices then you can have a look here for some ideas.

    www.inogic.com/.../get-current-location-from-the-device-in-dynamics-365

    There are some web Apis available to track the geo location information. You need to consume them as per your requirements. You can even use IP lookups API to track the country.

    developer.mozilla.org/.../Geolocation_API

    medium.com/.../how-to-detect-the-location-of-your-websites-visitor-using-javascript-92f9e91c095f

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    Hi Ankit,

    dynamics crm deosnt have any thing like this.

    you would require a very generic javascript. i.e using good API etc.

    Here few links i could find for you :  stackoverflow.com/.../find-user-location-using-jquery-js-without-google-geolocation-api  

    medium.com/.../how-to-detect-the-location-of-your-websites-visitor-using-javascript-92f9e91c095f

    tutorialzine.com/.../quick-tip-detecting-your-location-with-javascript

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans