Retrieve List Item Details

 function retrieveListItemDetails(listName, itemId) {

  // Get the current SharePoint context

  var context = SP.ClientContext.get_current();


  // Get the list

  var list = context.get_web().get_lists().getByTitle(listName);


  // Get the list item

  var listItem = list.getItemById(itemId);


  // Load the list item properties

  context.load(listItem);


  // Execute the query

  context.executeQueryAsync(

    function () {

      // On success, retrieve the item values

      var title = listItem.get_item('Title');

      var description = listItem.get_item('Description');


      // Concatenate the values into a query string parameter

      var queryStringParam = 'title=' + encodeURIComponent(title) +

        '&description=' + encodeURIComponent(description);


      // Pass the query string parameter to another application or redirect

      // Example: window.location.href = 'https://example.com/otherapp?' + queryStringParam;


      // Log the query string parameter for demonstration purposes

      console.log('Query string parameter:', queryStringParam);

    },

    function (sender, args) {

      // On error, log the error message

      console.log('Error:', args.get_message());

    }

  );

}


Comments

Popular posts from this blog

Sharepoint 2013 Script Editor web part CData for custom page layout using visual studio.

List attachment link in SharePoint 2013 search.

Bulk update and delete using SPservice in SharePoint