Skip to main content
Nintex Community Menu Bar

Create a list item from nintex form(JavaScript)

  • 17 September 2019
  • 2 replies
  • 162 views

Vinay_Katuri

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. Error: ' + args.get_message() + ' StackTrace: ' + args.get_stackTrace());
}
);
}

  • Just paste the code in the Nintex form settings-->Javascript code.
  • Save the code and publish the form.

2 replies

SimonMuntz
Nintex Employee
Forum|alt.badge.img+22
  • Nintex Employee
  • 2369 replies
  • September 17, 2019
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

naccarati
Forum|alt.badge.img+5
  • 42 replies
  • October 23, 2019
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.

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings