Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Right now I am using this method:

function getWebProperties(id) {
    var ctx = new SP.ClientContext.get_current();
    this.website = ctx.get_web();
    this.listCollection = website.get_lists();
    this.oList = listCollection.getByTitle('NavStructure');
    this.oItem = oList.getItemById(id);
    ctx.load(oItem, 'Include(Id, DisplayName)');
    ctx.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFail));
}

function onSuccess(sender, args) {
        alert("Title: " + oItem.get_displayName() + " ID: " + oItem.get_id());
}

function onFail(sender, args) {
        alert('failed to get list. Error:' + args.get_message());
}

But it keeps erroring out (through the onFail method) with:

failed to get list. Error:Invalid request

I also changed this line:

ctx.load(oItem, 'Include(Id, DisplayName)');

to

ctx.load(oItem);

And it errored out (in the browser. never fired the onFail method) with:

uncaught exception: [Exception... "'Error: 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 requested.' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "JS frame :: resource://firebug_rjs/net/spy.js :: callPageHandler :: line 796" data: no]

Can anyone see what I am doing wrong here?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Use ctx.load(oItem);

Then get the columns data using oItem.get_item('Title') OR oItem.get_item('ID')

I will try using ctx.load(oItem, 'Include(Id, DisplayName)'); and udpate the results in comments.

Hope this helps.

share|improve this answer
    
Just what I was looking for, thanks! –  Abe Miessler Aug 24 '11 at 18:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.