Pass a name from SharePoint 2010 to an assessment program using the Content Editor Web Part

My earlier post explained why you might want to pass in a name from SharePoint into an assessment program via the CEWP (Content Editor Web Part), and gave the JavaScript to do this in SharePoint 2007.

SharePoint 2010 has a Client Object Model which allows much more sophisticated JavaScript programming, and here is the JavaScript to do this in SharePoint 2010. (Thanks to Mike Smith of for putting me on the right track to find this.)

<iframe id="myframe" src="about:blank" height=600 width=600>

<script type="text/javascript">
var web;
var context;
var source;
function GetData() {
context = SP.ClientContext.get_current();
web = context.get_web();
user = web.get_currentUser();
context.executeQueryAsync(GetDataSuccess, GetDataFailed);

function GetDataSuccess(sender, args) {
source = '' + user.get_loginName();

function GetDataFailed(sender, args) {
alert('error: ' + args.get_message() + '\n' + args.get_stackTrace());
ExecuteOrDelayUntilScriptLoaded(GetData, "sp.js");

This is also available as a file to download. To use the file, replace the size of the iframe and the URL of the assessment system with your own. And upload it to your SharePoint site and reference it from a CEWP.

Here is a screenshot of it in use, showing user ICS\john2261 being passed through to the assessment.

SharePoint 2010 screenshot with CEWP

I was very proud to get this working! Many SharePoint users will use Windows Authentication or a custom webpart, but this route could provide an alternate route to provide simple pass through of participant name through to low stakes assessments, and I hope it’s helpful.

This entry was posted in How-To, SharePoint 2010 and tagged , , , , . Bookmark the permalink.

2 Responses to Pass a name from SharePoint 2010 to an assessment program using the Content Editor Web Part

  1. Illinger says:

    I’ve hit a bump with an app I’m building.
    I have a PHP site with Windows Authentication enabled in IIS, which works fine on its own. But, when I go to embed it into a CEWP I get the error “Cannot retrieve the URL specified in the Content Link property.” (Weird, since “Test Link” opens it right up, with a login dialog of course.) If I enable Anonymous Authentication, however, it does retrieve the page, but returns the SQL error instead “SQLSTATE[28000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user ‘NT AUTHORITY\IUSR’.1”. Its obvious in the later case that the CEWP is passing an annonymous security token, so I think that’s part of my problem.

    Is there a similar method to what you have here to pass the security token for the current user from SharePoint to the other app via CEWP?

    • johnkleeman says:


      When you use the CEWP or the Page Viewer Web Part, SharePoint doesn’t intrinsically pass authentication onto the called program. It just displays it in an iframe. What I’m doing here is taking the name of the SharePoint user and passing it in JavaScript on the command line to the URL. So this is not a secure means of authentication.

      If you are using IIS Windows Authentication, it should work to embed this in SharePoint – both apps separately authenticate against IIS (see for instance for an example), so I’m not sure why it’s not working for you when you embed it with the IIS authentication.

      Hope this helps a bit


Comments are closed.