I'm using SharePoint 2010. I need to get some SharePoint data on a list item hyperlink click. Inside the JavaScript file there is a method getLibraryGuid() I get the targetLibrary value with no issues using the executeQueryAsync().
But there seems to be an issue with the second call. The targetLibraryGuid call does not happen on the first item click. I observed that it is retrieved on the second click attempt on the item in the list view. Am i missing any point here?
Also, in the status bar in IE i get 2 error messages saying:
1) The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly executed 2) Object doesn't support this property or method
[from the sp.runtime.debug.js]
function getLibraryGuid(libraryName) {
//1st call
var targetLibrary = context.get_web().get_lists().getByTitle(libraryName);
context.load(targetLibrary);
context.executeQueryAsync(
function(sender, args) {
},
function(sender, args) {
alert('Request Failed' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}, "sp.js");
//2nd call
targetLibraryGuid = targetLibrary.get_id().toString();
context.load(targetLibraryGuid);
context.executeQueryAsync(
function(sender, args) {
},
function(sender, args) {
alert('Request Failed' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}, "sp.js");
alert('library guid : ' + targetLibraryGuid);
}