Get current user id using JavaScript in Dynamics 365 CE CRM script
To get current user id you can use the following script: This will return GUID with curly braces.
var userSettings = Xrm.Utility.getGlobalContext().userSettings;
var currentuserid = userSettings.userId;
var username = userSettings.userName;
var securityrolesofcurrentuser = userSettings.securityRoles;
To get current user name you can use the following script:
var userSettings = Xrm.Utility.getGlobalContext().userSettings;
var username = userSettings.userName;
To get current user roles you can use the following script: Returns an array of strings that represent the GUID values of each of the security role or teams that the user is associated with.
var userSettings = Xrm.Utility.getGlobalContext().userSettings;
var securityrolesofcurrentuser = userSettings.securityRoles;