I wrote javascript for getting list items but here I'm hard coded list name as "Projects"(my list name). How can I get list name automatically with out hard coding,

function DoLogicalDelete()

    var clientContext = null;
    var oList = null;
    var oListItem = null;
   //var lstItmIsDeleted = null;

    var itmID = getQuerystring('ID');

    clientContext = SP.ClientContext.get_current();

    oList = clientContext.get_web().get_lists().getByTitle('Projects');

    //var oListItemID = SP.ListOperation.Selection.getSelectedItems(clientContext);

    oListItem = oList.getItemById(itmID);                         // getting ID

    clientContext.load(oListItem,"Title", "IsDeleted");            // load items to oListItem

    oListItem.set_item('IsDeleted', true);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed)); 

Appreciate if anyone help.

Thank you.

  • Where are you writing this code? – Nadeem Yousuf-AIS Feb 28 '14 at 5:35
  • Hi Vardhaman,Actually added one button(not on ribbon. took sp action button ) to Dispform aspx page. When I click on button , IsDeleted checkbox will change no to yes. Here I want to write this globally thats why I'm asking instead of 'Projects'(my list name) what I have to write? – Flying Hope Feb 28 '14 at 5:56

You could change

oList = clientContext.get_web().get_lists().getByTitle('Projects'); 


oList = clientContext.get_web().get_lists().getById(_spPageContextInfo.pageListId)
  • Where did you get that information? Maybe it is so in SP2010? Since I specifically checked it in display form of a custom list and the property was there in SP2013. – Rae23 Mar 2 '14 at 17:55
var listTitle = _spPageContextInfo.listTitle;

Works for forms in 2019 On Prem. Haven't tried in 2013/2016 but I bet it works there too.

  • Can confirm is works in SharePoint Online. Thanks for posting - saved me a lot of work! – Jimmy Nov 20 '20 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.