SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
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

You could change

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

to

oList = clientContext.get_web().get_lists().getById(_spPageContextInfo.pageListId)
share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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