0

I had written the code to insert the values in sharepoint list,And I was unable to to perform the operation.When I check step by step using "alert" then I see error as "[Object Object]" . Below is my written JSOM Script,Can any one help me in knowing why I am facing the error and what's wrong in my below code

<script>
alert('start script');
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', addlistitems);

function addlistitems()
{

alert('in Add Function');
var clientContext = new SP.ClientContext.get_current();

var myList = clientContext.get_web().get_lists().getByTitle('PRF');
alert(myList);

}
</script>
  • alert can only show Strings.. quickly learn to use console.log (or .info or .error) statements. – Danny '365CSI' Engelman Apr 17 '16 at 18:28
0

Try this code from MSDN: https://msdn.microsoft.com/en-us/library/office/jj163201.aspx

function createListItem(siteUrl) {
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Announcements');

    var itemCreateInfo = new SP.ListItemCreationInformation();
    this.oListItem = oList.addItem(itemCreateInfo);
    oListItem.set_item('Title', 'My New Item!');
    oListItem.set_item('Body', 'Hello World!');
    oListItem.update();

    clientContext.load(oListItem);
    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded), 
        Function.createDelegate(this, this.onQueryFailed)
    );
}

function onQuerySucceeded() {
    alert('Item created: ' + oListItem.get_id());
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());
}
|improve this answer|||||

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.