Create New Listitem onSubmit of NewForm
Posted: 01 Aug 2018
Hi,
After creating a new product (Onsubmit - NewForm_product) i have to create a new listitem in a different List(product_xy) and refrence this listitem with the ID from the created product!
(....for each productgroup i have to create a separat list due to the fact i´m having about 500 different product-attributes(columns) which is not possible to store in one List!!!)
I´m able to create the new Listitem (product_xy) with this code:
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', createListItem);//makes sure sp.js is loaded and then calls createListItem method
function createListItem() {
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('P_RP_Turbine');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Product_LU', ID from newly created product);
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());
}
My question:
How to get the "ID from newly created product" to pass it to the createListItem()-function ?
..after this i want to redirect to the Edit_Form of product_xy-list
i would do this with:
var uri = fd.setUrlParam(decodeURIComponent(window.location.href), 'FDRedirectWithID', Edit_Form of product_xy-list.aspx?ID=');
fd.sourceFormParam(uri);
Thank´s for helping me.
Johannes
After creating a new product (Onsubmit - NewForm_product) i have to create a new listitem in a different List(product_xy) and refrence this listitem with the ID from the created product!
(....for each productgroup i have to create a separat list due to the fact i´m having about 500 different product-attributes(columns) which is not possible to store in one List!!!)
I´m able to create the new Listitem (product_xy) with this code:
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', createListItem);//makes sure sp.js is loaded and then calls createListItem method
function createListItem() {
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('P_RP_Turbine');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Product_LU', ID from newly created product);
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());
}
My question:
How to get the "ID from newly created product" to pass it to the createListItem()-function ?
..after this i want to redirect to the Edit_Form of product_xy-list
i would do this with:
var uri = fd.setUrlParam(decodeURIComponent(window.location.href), 'FDRedirectWithID', Edit_Form of product_xy-list.aspx?ID=');
fd.sourceFormParam(uri);
Thank´s for helping me.
Johannes