Question

I want to get item ID immediately after click button SAVE. I need this for export in word item data.

1) Click Save, get saved item ID and PRINT i want this is one button event.

Était-ce utile?

La solution 4

This code solve my problem. Thank you!

itemAdd.Update();
currItemID = Convert.ToString(itemAdd.ID)

Autres conseils

You can manually save your item, look at this code

$("input[value='Salvar']").removeAttr("onclick");
$("input[value='Salvar']").on("click", function (e) {
    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle("listName");
    var itemCreateInfo = new SP.ListItemCreationInformation();
    var oListItem = oList.addItem(itemCreateInfo);


    oListItem.set_item("title", $("input[title='Title']").val());
    oListItem.update();

    clientContext.load(oListItem);
    clientContext.executeQueryAsync(Function.createDelegate(this, function () {             
        console.log(oListItem.get_id());
    }), Function.createDelegate(this, function (sender, args) {
        console.log("error");
    }));            
});

this is a custom newform.aspx using jQuery.

I am not sure about the 'PRINT' you have stated above (where? Display the item on other column, display it on email, etc?). But if you need the ID after submit, you could attach an event receiver to your list:

https://msdn.microsoft.com/en-us/library/ff398052.aspx

You could also do this by attach a list workflow to your list and set the workflow to run when new item is created. Then inside the workflow, you could get the reference to your newly created item and of course you could get the ID.

1) You can use below function on PRINT button to get newly created Id.

function getNewItemID(listname){
var itemID=0;
var siteURL = _spPageContextInfo.webAbsoluteUrl;

var url = siteURL + "/_api/web/lists/getbytitle('" + listname + "')/items?$select=ID&$OrderBy=Created desc&$top=1";
$.ajax({
 url: url,
 method: "GET",
 async: false,
 headers: { "Accept": "application/json; odata=verbose" },
 success: function (data) {
    if(data.d.results.length>0){
        itemID = data.d.results[0].ID;
    }   
 },
 error: function (data) {       
 }
});
return itemID;
}

OR

2) Go for Workflow or Item Event Reciever

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top