1

I am new to Javascript and Sharepoint 2013. I am following a tutorial and I created a lab exercise, in it I am adding a new item/record/row in a list via Javascript.

In this example the list is created in Hostweb and I am accessing it in SharePoint App i.e. in AppWeb. In the lab exercise code was written in the App.JS file, I used the same code but placed the whole code in new JS file as App1.JS and called the function of App1.JS at the document.ready function of App.JS.

The code works fine if the code is placed in App.JS but fails when it is called from App1.JS and it gives the following error: **

  • "JavaScript runtime error: Object doesn't support property or method 'add_requestSucceeded'"

the code is :

function createCategory() {
    var ctx = new SP.ClientContext(appWebUrl);//Get the SharePoint Context object based upon the URL
    var appCtxSite = new SP.AppContextSite(ctx, hostWebUrl);

    var web = appCtxSite.get_web(); //Get the Site 

    var list = web.get_lists().getByTitle("CategoryList"); //Get the List based upon the Title
    var listCreationInformation = new SP.ListItemCreationInformation(); //Object for creating Item in the List
    var listItem = list.addItem(listCreationInformation);

    listItem.set_item("Title", $("#CategoryId").val());
    listItem.set_item("CategoryName", $("#CategoryName").val());
    listItem.update(); //Update the List Item

    ctx.load(listItem);
    //Execute the batch Asynchronously
    ctx.executeQueryAsync(
        Function.createDelegate(this, success),
        Function.createDelegate(this, fail)
       );
}

Can someone please tell me the cause of the error and suggest its solution.

  • You can refer to MSDN to learn more about JSOM – nbi Jul 20 '15 at 8:53
1

Please create a method success in your JS file. This arises when JS is not able to find the the specified method.

ctx.executeQueryAsync(
    Function.createDelegate(this, success),
    Function.createDelegate(this, fail)
   );

function success(){
 // executable lines
}

function fail(sender,args){
//executable lines
}
  • Hi, Thanks for the reply but I already created Success and Fail methods: function success() { $("#dvMessage").text("Operation Completed Successfully"); } function fail() { $("#dvMessage").text("Operation failed " + arguments[1].get_message()); } – user31823 Jul 20 '15 at 9:06
  • could you please share the complete code. Is there any method with name 'add_requestSucceeded' in your code? Or tried to delete the cache of the browser. – nbi Jul 20 '15 at 9:10
  • Hi, I found the error, I wrongly defined the function in App.JS file which was calling the App1.JS. Thanks for your support – user31823 Jul 20 '15 at 10:09

Your Answer

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

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