Hello and thanks in advance for the help.
I Have a list with 2 columns, Title
and IntakeID
. I'm attempting to get the next ID
in the SharePoint list and input it to the IntakeID
field in the newform.aspx
.
I have been successful with my script with the exception that each time I add a new item, each item ID
is appended.
For example:
Last Item ID
added in list = 6
Add New item the 1st time: value =7
Add New item 2nd time: value = 78
Add New item 3rd time: value = 789
Add New item 4th time: value = 78910
Any help would be greatly appreciated. Thanks!
All I want to return is just the next ID
which is 7 in this example.
<script src="http://MYSharePoint.com/sites/TestSite/SiteAssets/Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
ExecuteOrDelayUntilScriptLoaded(GetListItemId, "sp.js");
});
function GetListItemId() {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('Separation Intake Form');
var query = SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(query);
context.load(allItems);
context.executeQueryAsync(Function.createDelegate(this, this.successGetListItemId));
}
function successGetListItemId() {
var TextField = "";
var ListEnumerator = this.allItems.getEnumerator();
while (ListEnumerator.moveNext()) {
var currentItem = ListEnumerator.get_current();
TextField += currentItem.get_item('ID');
}
alert("Adam Testing next ID: " + TextField);
$("input[title='IntakeID']").val(TextField);
$("input[title='IntakeID']").attr("readonly","true").css('background-color','#F6F6F6');
}
</script>