Quantcast
Channel: jQuery Library for SharePoint Web Services
Viewing all articles
Browse latest Browse all 6517

Edited Task: SPGetCurrentUser not being async [10189]

$
0
0
From https://spservices.codeplex.com/discussions/463376

It could be async, but the function is simple, and I don't want to assume that people understand program flow with this one.

That said, I should respect the value of async if it's passed in. I'll do a fix for the next release. In the meantime, you could patch your version:

```
// Function which returns the account name for the current user in DOMAIN\username format
$.fn.SPServices.SPGetCurrentUser = function(options) {

var opt = $.extend({}, {
webURL: "", // URL of the target Site Collection. If not specified, the current Web is used.
fieldName: "Name", // Specifies which field to return from the userdisp.aspx page
fieldNames: {}, // Specifies which fields to return from the userdisp.aspx page - added in v0.7.2 to allow multiple columns
debug: false // If true, show error messages; if false, run silent
async: false
}, options);

// The current user's ID is reliably available in an existing JavaScript variable
if(opt.fieldName === "ID" && typeof SPServicesContext.thisUserId !== "undefined") {
return SPServicesContext.thisUserId;
}

var thisField = "";
var theseFields = {};
var fieldCount = opt.fieldNames.length > 0 ? opt.fieldNames.length : 1;
var thisUserDisp;
var thisWeb = opt.webURL.length > 0 ? opt.webURL : $().SPServices.SPGetCurrentSite();

// Get the UserDisp.aspx page using AJAX
$.ajax({
// Need this to be synchronous so we're assured of a valid value
async: opt.async,
// Force parameter forces redirection to a page that displays the information as stored in the UserInfo table rather than My Site.
// Adding the extra Query String parameter with the current date/time forces the server to view this as a new request.
url: thisWeb + "/_layouts/userdisp.aspx?Force=True&" + new Date().getTime(),
complete: function (xData) {
thisUserDisp = xData;
}
});

```

M.

Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>