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.