function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MittopMittop 

I feel like I am being stupid, but I can't get the UserID of the current User in the S-Control

Need a hand with this one. I am trying to use the API Utility call in Javascript to get the Current User ID.

I have been using some test code just to get a result, and it keeps saying undefined. I have tried the following.

function initPage() {
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", false);
var uInfo = sforceClient.GetUserInfo();
alert(uInfo.getUserId()));
loadPage();
}

function initPage() {
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", false);
var uInfo = sforceClient.GetUserInfo();
alert(uInfo.getUserId);
loadPage();
}

function initPage() {
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", false);
var uInfo = sforceClient.GetUserInfo();
alert(uInfo.get("userID"));
loadPage();
}

None of these work. What am I missing? Anyone point me in the right direction?

Thanks!

Mittop
 
Doug ChasmanDoug Chasman
No need to incur the round trip to the server - you can get what you need using merge fields that are replaced server side when the scontrol content is retrieved: {!User_Username}, {!User_ID}, etc
MittopMittop
I had tried that, but now I realize that I was using {!UserId} which of course does not work.

Is there a post anywhere with a list of which merge fields are included to access in the s-control?

Thanks for your help!

Mittop
gsickalgsickal
go to setup where your scontrol is.   click on edit and you'll see some drop downs which based on what object you select will tell you what the available merge fields are.
MittopMittop
Thanks everyone.

Just curious, what was I doing wrong calling the GetUserInfo function?
gsickalgsickal

Look at sforceclient_beta3.3.js.  In it you will see that functions and Javascript are case-sensitive.  Thus you need to use "getUserInfo", not "GetUserInfo".  Here is the code you can use to replace what you have to inspect the fields from the UserInfoResult:

Code:

    // sample code to getUserInfo
    var ui = sforceClient.getUserInfo(); 
    alert("UserInfoResult = " + ui);
    if (ui.className == "UserInfoResult") {
     var userId = ui.userId;
     var fullName = ui.userFullName;
     var email = ui.userEmail;
  alert("userId = " + userId + "\nuserFullName = " + fullName + "\nuserEmail = " + email);
    } else {
     alert("getUserInfoError: " + ui.detail.fault.exceptionMessage);
    }


 

MittopMittop
You sir are, as they say, awesome.

Thanks!

Mittop