I need to lookup the current user's login name, then use the result to get the ID of a list item that has a column containing that login name.

I'm still brand new to javascript, so the code below might be ridiculous. It's what I've cobbled together from various articles. Oh, and it needs to work in SP 2007. Thanks in advance!

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">

function GetUserName()
var wshell = new ActiveXObject("WScript.Shell");
var username = wshell.ExpandEnvironmentStrings("%USERNAME%");
var queryLookup = "<Query><Where><Eq><FieldRef Name='PinExtract'/><Value Type='Text'>"+username +"</Value></Eq></Where></Query>";
var itemID="";
operation: "GetListItems",
async: false,
listName: "UserList",
CAMLViewFields: "<ViewFields><FieldRef Name='ID'/></ViewFields>",
CAMLQuery: queryLookup,
completefunc: function(xData,Status) { 
itemID = $(xData.responseXML.xml).find("z\\:row").attr("ows_ID");


PS: I asked a pretty massive question earlier, and was advised I should probably break it up into smaller pieces if I want to get it answered (BUT, if you want a challenge, here's the full issue: Javascript to: get username, lookup id in list, then update list item)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.