Skip to main content
Java script for downloading an attachment in a based on seach used in display template.

 getAttachements: function (siteUrl, listId, itemId) {
           console.log("siteUrl " + siteUrl);
           console.log("listId " + listId);
           console.log("itemId " + itemId);
           
           doSpAction(function() { 
              console.log("doing sp action"); 
              
              var clientContext = new SP.ClientContext(siteUrl);
//                      var list = cx.get_web().get_lists().getByTitle("Bestillinger");
              var productList = clientContext.get_web().get_lists().getById(listId);
              var targetItem = productList.getItemById(itemId);
              clientContext.load(targetItem, "Title");
  /*            cx.executeQueryAsync(
            Function.createDelegate(this, successHandler),
            Function.createDelegate(this, errorHandler)
        ); */
              clientContext.executeQueryAsync(
                Function.createDelegate(this, listLoaded),
                Function.createDelegate(this, listFailedToLoad)
              );
              
              function listLoaded() {
                 var allAtt = targetItem.get_attachmentFiles();
                 
                 clientContext.load(allAtt);
                 
                 clientContext.executeQueryAsync(
                     function () {
                        handleAtta(allAtt);
                     },
                     Function.createDelegate(this, listFailedToLoad)
                 );
                 
                 //console.log(allAtt);
              };
              
              function listFailedToLoad() {
                 console.log(
                 "Request failed: " + arguments[1].get_message());
              };
              
              function handleAtta(allAtt) {
                 console.log(allAtt);
                 
                 var enumerator = allAtt.getEnumerator();
                 
                 while (enumerator.moveNext()) {
                    var current = enumerator.get_current();
                    var path = current.get_serverRelativeUrl();
                    
                    var fileName = current.get_fileName();
                    
                    $("#"+ itemId +"attlink").attr("href", path);
                  
                    console.log(current);
                    console.log(path);
                    console.log(fileName);
                 };
              };
           });
        }

Comments

Popular posts from this blog

Getting the script folder in PowerShell

Today I needed to call another script file in the same folder as the main script. After a little searching on the web I found "$MyInvocation.MyCommand.Path". "$MyInvocation.MyCommand.Path" returns the path to the current script, With that I was able to get the current folder using Get-Item. This is my test scripts: ToRun.ps1: Write-Host $MyInvocation.MyCommand.Path $scriptDirectory  = (Get-Item $MyInvocation.MyCommand.Path).DirectoryName $scriptName = "HelloWorld.ps1" Write-Host calling $scriptName in $scriptDirectory & ($scriptDirectory + '\' + $scriptName) HelloWorld.ps1: Write-Host "Hello word" After running the script the output was: calling HelloWorld.ps1 in C:\scriptFun Hello word Simple but useful.

Using azure event gird with a function app

Introduction In this tutorial we will set up a simple azure event grid topic, with an function app as a subscriber to the topic. The function app will just log the messages, so we can se that it picked up the event. Setting things up First step is to create a resource group where we can add all the azure services we need az group create --name  myresourcegroup   --location norwayeast We need to set up a storage account that can be used bye the function app. az storage account create --name mystorageaccount --resource-group myresourcegroup --location eastus --sku Standard_LRS Now that we have a storage account we can make the function app. Here we will set it up to be able to run .Net 6 functions az functionapp create --name myFunctionApp --resource-group  myresourcegroup  --consumption-plan-location eastus --runtime dotnet --runtime-version 6.0 --functions-version 4 --storage-account  mystorageaccount...