Wednesday, February 11, 2015

Stuck in stupid with the error "Object does not support this method..."

Sometime I got the stuck in coding and it seems taking waste time to google or ask for help in forum. Eventually I found the stupid reason that I don't think about the basically knowledge.

Look at the code:


var clientContext = SP.ClientContext.get_current();
var list = clientContext.get_web().get_lists().getByTitle(context.ListTitle);
                
I got the error "Object does not support this method..." bla bla bla. Now, I know you will ask me in your mind the question is where the code is put in! For being time, I cannot answer your question unless I could resolve the problem.

After doing a forage in the internet, I remember the terrible reality suddenly. I forgot initializing the object SP.ClientContext in the sp.js! Wow hooooo....That code was changed:



SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
        var clientContext = SP.ClientContext.get_current();
        var list = clientContext.get_web().get_lists().getByTitle(context.ListTitle);
               .....
});
                

Done!
Everything is resolved!