1

I want to add list item through custom form using asynchronous javascript but i cant able to show any message on page that item created or not

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', createItem);//makes sure sp.js is loaded and then calls createListItem method
function createItem() {
    var clientContext = new SP.ClientContext.get_current();//if the page and the list are in same site.If list is in different site then use relative url instead of get_current
    var oList = clientContext.get_web().get_lists().getByTitle('Vendor');

    var itemCreateInfo = new SP.ListItemCreationInformation();
    oListItem = oList.addItem(itemCreateInfo);
    oListItem.set_item("Title", $('#RVendorDiv').val());

    oListItem.update();

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

function onQuerySucceeded() {
    alert('Item created successfully ' );
}

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

You will need to use CSOM-JS.

Refer to this post on how your HTML form should look like and this on how to do basic JavaScript operations in SharePoint 2013 or SharePoint 2010.

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.