Vinay_Katuri
Canvas Initiate

Create a list item from nintex form(JavaScript)

Title: There is one nintex form containing buttons(Save,Cancel and Create). If we click on Create button a new copy of this record will be created using JavaScript(Client context)

Steps:

We can easily create a new list item by using Javascript by following below steps.

  • Firstly Create all the javascript variables for the fields that need to be filled in the new item.
  • Write the javascript code by using ClientContext to create a new item as shown below

    function CreateNewListItem(){
    var ctx = new SP.ClientContext.get_current();
    var oList = ctx.get_web().get_lists().getByTitle('List Name');
    var itemCreateInfo = new SP.ListItemCreationInformation();
    this.oListItem = oList.addItem(itemCreateInfo);

    var sys = NWF$('#' + System).val(); \\ System is the fields javascript class in the form

    var doctype = NWF$('#' + DocType).val(); \\  Doctype is the fields javascript class in the form

        var dept = NWF$('#' + Department).val(); \\  Department is the fields javascript class in the form
oListItem.set_item('System',sys); \\System is a field in the list
oListItem.set_item('Dctype',doctype); \\ Dctype is a field in the list
oListItem.set_item('Dept',dept); \\ Dept is a field in the list
oListItem.update();
ctx.executeQueryAsync(
function() {
alert('success...! Copy of this document is Created');
},
function(sender, args) {
alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}
);
}

  • Just paste the code in the Nintex form settings-->Javascript code.
  • Save the code and publish the form.
0 Kudos
Reply
2 Replies
SimonMuntz
Nintex Employee
Nintex Employee

Re: Create a list item from nintex form(JavaScript)

Hi,
I noticed you have put together a few of these how to's.
You might want to consider adding them to the Blog section of the community. https://community.nintex.com/t5/Community-Blogs/bg-p/Tech_Blog
0 Kudos
Reply
naccarati
Workflow Hero

Re: Create a list item from nintex form(JavaScript)

Hello,
Having issues with this. It's not working. Any ideas why? I've replaced the 'List Name', put in our variables to hold the data and write it to the new item, changed the oListItem.set_item. It looks like it's executing when the button is clicked, but it's not.
0 Kudos
Reply