Get logged in user details
-
11 Nisan 2012 Çarşamba 10:43
Hi,
I have a requirement of knowing when a user is logged in and i want to save these details. How can i do this.
Can we fire a javascript when user login to crm 2011 online.
Tüm Yanıtlar
-
11 Nisan 2012 Çarşamba 10:52
Hi,
You can get current user and the name from JavaScript:
If you want to get current user id in crm 2011 form you can use Xrm.Page.context, you have to use
getUserId() method for this you can use it like belowXrm.Page.context.getUserId()
But if you want to get current user name then you can use below function to retrieve it
function Getinfo() {
var context;
var serverUrl;
var UserID;
var ODataPath;
context = Xrm.Page.context;
serverUrl = context.getServerUrl();
UserID = context.getUserId();
ODataPath = serverUrl + “/XRMServices/2011/OrganizationData.svc”;
var retrieveUserReq = new XMLHttpRequest();
retrieveUserReq.open(“GET”, ODataPath + “/SystemUserSet(guid’” + UserID + “‘)”, true);
retrieveUserReq.setRequestHeader(“Accept”, “application/json”);
retrieveUserReq.setRequestHeader(“Content-Type”, “application/json; charset=utf-8″);
retrieveUserReq.onreadystatechange = function () {
retrieveUserReqCallBack(this);
};
retrieveUserReq.send();}
function retrieveUserReqCallBack(retrieveUserReq) {
if (retrieveUserReq.readyState == 4 /* complete */) {
if (retrieveUserReq.status == 200) {
var retrievedUser = this.parent.JSON.parse(retrieveUserReq.responseText).d;
if (retrievedUser.FullName!= null)
alert(retrievedUser.FullName);
}
else {
alert(“Error in Fetching User data”);
}
}
}I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Ashish Mahajan, CRM Developer, CSG (Melbourne)
My Personal Website: http://www.ashishmahajan.com
My Blogs: http://ashishmahajancrm.blogspot.com.au and http://ashishmahajancrm.wordpress.com
My Youtube Channel: http://www.youtube.com/user/ashishmahajanmscrm
My Twitter: https://twitter.com/#!/ashishmahajan74My Linkedin: 
- Yanıt Olarak Öneren Ashish Mahajan Australia (Architect) 11 Nisan 2012 Çarşamba 10:52
-
11 Nisan 2012 Çarşamba 11:01
can i call this function when the user login to crm 2011 online
-
11 Nisan 2012 Çarşamba 11:06
Hi,
I never tried online. It works on premises.
Try it out. You might need to tweak a bit.
Ashish Mahajan, CRM Developer, CSG (Melbourne)
My Personal Website: http://www.ashishmahajan.com
My Blogs: http://ashishmahajancrm.blogspot.com.au and http://ashishmahajancrm.wordpress.com
My Youtube Channel: http://www.youtube.com/user/ashishmahajanmscrm
My Twitter: https://twitter.com/#!/ashishmahajan74My Linkedin: 
- Yanıt Olarak Öneren Ashish Mahajan Australia (Architect) 11 Nisan 2012 Çarşamba 11:07
-
11 Nisan 2012 Çarşamba 23:14Hi,
If the response answered your question and you are satisfied, please mark the response as an answer. This will help others to search on similar problems.
Thanks in advance.Ashish Mahajan, CRM Developer, CSG (Melbourne)
My Personal Website: http://www.ashishmahajan.com
My Blogs: http://ashishmahajancrm.blogspot.com.au and http://ashishmahajancrm.wordpress.com
My Youtube Channel: http://www.youtube.com/user/ashishmahajanmscrm
My Twitter: https://twitter.com/#!/ashishmahajan74My Linkedin: 
-
31 Mayıs 2012 Perşembe 11:47
Hi . Ashish,
i tried your following code in on premises... But i am getting error msg.
-
31 Mayıs 2012 Perşembe 11:51
Hi,
Have you saved this function as a JScript web resource and then loading this on the onload event of the form?
I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Ashish Mahajan, Microsoft Dynamics CRM Solutions Architect, CSG (Melbourne)
My Personal Website: http://www.ashishmahajan.com
My Blogs: http://ashishmahajancrm.blogspot.com.au and http://ashishmahajancrm.wordpress.com
My Youtube Channel: http://www.youtube.com/user/ashishmahajanmscrm
My Twitter: https://twitter.com/#!/ashishmahajan74My Linkedin: 
- Yanıt Olarak Öneren Ashish Mahajan Australia (Architect) 31 Mayıs 2012 Perşembe 11:51
-
31 Mayıs 2012 Perşembe 19:05
Do you have Auditing enabled in your CRM system?
As a CRM Administrator, I go into they CRM system every day to the Auditing section of Settings/System and check who is in the system and what they are doing (i.e. updating, creating, editing).
Just a thought.
Windy
- Yanıt Olarak Öneren pogo69 31 Mayıs 2012 Perşembe 20:28
-
01 Haziran 2012 Cuma 10:14
yes i have saved and kept in on load function . but i am getting "Error In fetching User Data".
This the code...
function Getinfo()
{
var context;
var serverUrl;
var UserID;
var ODataPath;
context = Xrm.Page.context;
serverUrl = "http://xxxxx/xxxxxx";
UserID = context.getUserId();
ODataPath = serverUrl + "/XRMServices/2011/Organization.svc";
var retrieveUserReq = new XMLHttpRequest();
retrieveUserReq.open("GET", ODataPath + "/SystemUserSet(guid'" + UserID + "')", true);
retrieveUserReq.setRequestHeader("Accept", "application/json");
retrieveUserReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveUserReq.onreadystatechange = function () {
retrieveUserReqCallBack(this);
};
retrieveUserReq.send();
}
function retrieveUserReqCallBack(retrieveUserReq)
{
if (retrieveUserReq.readyState == 4 /* complete */) {
if (retrieveUserReq.status == 200) {
var retrievedUser = this.parent.JSON.parse(retrieveUserReq.responseText).d;
if (retrievedUser.FullName!= null)
alert(retrievedUser.FullName);
//To check picklist
if(retrievedUser.AccessMode!=null)
alert(retrievedUser.AccessMode.Value); // for picklist we need to check value
}
else {
alert("Error in Fetching User data");
}
}
} -
01 Haziran 2012 Cuma 10:22
Why do you not use the default functionality of Microsoft CRM 2011?
In Settings -> Administration -> System Settings -> Auditing
You can set the value of Audit User Access to true. Then the logins will be automaticly tracked.
Rune Daub Senior Consultant - Dynateam CRM http://www.xrmmanagement.com