Posts

Showing posts from 2023
 <script type="text/javascript"> function uploadFileAsAttachment(itemId, fileInput) {   var file = fileInput.files[0];      if (file) {     var context = SP.ClientContext.get_current();     var web = context.get_web();     var list = web.get_lists().getByTitle("Your List Name");     var listItem = list.getItemById(itemId);          // Read the file data     var reader = new FileReader();          reader.onloadend = function (evt) {       if (evt.target.readyState == FileReader.DONE) {         // Create a new file creation information object         var attachmentInfo = new SP.AttachmentCreationInformation();         attachmentInfo.set_contentType(file.type);         attachmentInfo.set_fileName(file.name);         attachmentInfo.set_attachmentContent(new SP.Base64EncodedByteArray());                  // Convert the file data to byte array         var byteArray = new Uint8Array(evt.target.result);                  for (var i = 0; i < byteArray.byteLength; i++
 <script type="text/javascript"> function uploadFile() {   var fileInput = document.getElementById("fileInput");   var file = fileInput.files[0];      if (file) {     var context = SP.ClientContext.get_current();     var web = context.get_web();     var list = web.get_lists().getByTitle("Your List Name");     var folder = list.get_rootFolder();          context.load(folder);          // Read the file data     var reader = new FileReader();          reader.onloadend = function (evt) {       if (evt.target.readyState == FileReader.DONE) {         // Create a new file creation information object         var fileInfo = new SP.FileCreationInformation();         fileInfo.set_url(file.name);         fileInfo.set_content(new SP.Base64EncodedByteArray());                  // Convert the file data to byte array         var byteArray = new Uint8Array(evt.target.result);                  for (var i = 0; i < byteArray.byteLength; i++) {           fileInfo.get_

Sample HTML

 <!DOCTYPE html> <html> <head>   <title>SharePoint Layout with Glassy Look</title>   <style>     body {       background-color: #800000; /* Maroon background color */       color: #FFFFFF; /* White text color */       font-family: Arial, sans-serif;       margin: 0;       padding: 0;     }     .container {       max-width: 960px;       margin: 0 auto;       padding: 20px;       background-color: rgba(255, 255, 255, 0.8); /* Semi-transparent white background */       box-shadow: 0 0 10px rgba(0, 0, 0, 0.3); /* Glassy box shadow */     }     h1, h2, h3 {       margin: 0;     }     .content {       margin-top: 20px;     }   </style> </head> <body>   <div class="container">     <h1>Welcome to SharePoint</h1>     <div class="content">       <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>       <p>Donec at dapibus nisi. Vestibulum cursus dui vel fringilla conseq

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 str

Javascript function to populate from query string

 function populateFieldsFromQueryString() {   // Get the query string from the URL   const queryString = window.location.search;   // Check if there is a query string   if (queryString) {     // Remove the leading "?" character     const queryParams = queryString.substring(1);     // Split the query string into key-value pairs     const keyValuePairs = queryParams.split("&");     // Loop through the key-value pairs     keyValuePairs.forEach((pair) => {       // Split each pair into key and value       const [key, value] = pair.split("=");       // Decode the key and value (in case of URL encoding)       const decodedKey = decodeURIComponent(key);       const decodedValue = decodeURIComponent(value);       // Find the corresponding field in the document       const field = document.querySelector(`[name="${decodedKey}"]`);       // Check if the field exists       if (field) {         // Populate the field with the value         field.value =
 Concat(     GroupBy(         'CollectionName',         "IdentityColumn",         "GroupedData",         "NameColumn"     ),     If(         CountRows("GroupedData") = 1,         "GroupedData[@NameColumn]",         Concatenate(             "GroupedData[@NameColumn]",             ", ",             "GroupedData[@NameColumn]",             GroupedData,             ", "         )     ),     " " )
To convert a column of folder paths into a tree structure of rows, you can use a combination of Excel formulas and VBA code. Here are the steps to follow: Insert a new column to the right of the column with the folder paths. In the first cell of the new column, enter the formula =LEN(A1)-LEN(SUBSTITUTE(A1,"\","")) , where A1 is the first cell in the column with the folder paths. This formula calculates the number of backslashes in the folder path. Copy the formula down the entire column to calculate the number of backslashes in each folder path. Insert a new sheet in the workbook and name it "Tree". In the "Tree" sheet, create headers for the columns "Level 1", "Level 2", "Level 3", etc. up to the maximum number of levels in your folder paths. For example, if your folder paths have a maximum of 3 levels, create columns for "Level 1", "Level 2", and "Level 3". In the first cell of each co
 async function getListItems(listUrl: string) {   const apiUrl = `${listUrl}/items?$top=5000`;   const items = [];   let skipToken = null;   do {     const url = skipToken ? `${apiUrl}&$skiptoken=${encodeURIComponent(skipToken)}` : apiUrl;     const response = await fetch(url, {       headers: {         Accept: "application/json;odata=nometadata"       }     });     const data = await response.json();     items.push(...data.value);     skipToken = data["@odata.nextLink"] ? data["@odata.nextLink"].split("&$skiptoken=")[1] : null;   } while (skipToken);   return items; } const listUrl = "https://<your-site-url>/_api/web/lists/getByTitle('<your-list-title>')" ; const items = await getListItems(listUrl); const filteredItems = items. filter ( item => { return filters. every ( filter => item[filter. property ] === filter. value ); }); const filters = [ { property : "Status" , valu