2

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);
    oListItem.update();

    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 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
4

You could change

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

to

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

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.