Blog

Sharepoint REST set ShowInEditForm

On 28/11/2019

With this script you can Show / hide your field in standard sharepoint forms
ShowInDisplayForm
ShowInEditForm
ShowInNewForm
 
var xhr = new XMLHttpRequest();
var url = _spPageContextInfo.webAbsoluteUrl;
if (url === "undefined {
console.log("_spPageContextInfo.webAbsoluteUrl undefined");
url = "http://siteUrl;
}
 
xhr.open('POST', url + "/_api/web/Lists(guid'bec2b6d5-3183-4bd7-87a5-0989610b2e25')/Fields(guid'341eeecb-e5ff-447c-9cd0-84c9f00c80c6')/setShowInEditForm(true)");
xhr.setRequestHeader("Accept", "application/json; odata=verbose");
xhr.setRequestHeader("X-RequestDigest", document.getElementById("__REQUESTDIGEST").value;
xhr.setRequestHeader("X-HTTP-Method", "MERGE");
xhr.setRequestHeader("If-Match", "*");
 
xhr.onload = function () {
if (xhr.status === 200) {
var kk = JSON.parse(xhr.responseText);
console.dir(kk);
}
else {
console.dir(xhr);
alert('Request failed. Returned status of ' + xhr.status);
}
};
xhr.send();
 
see script in mode text here

Sharepoint Query Using REST

On 27/11/2019

Here is my page to develop my REST queries

if my query returns an object, it will display all properties of my obj, as in navigation console (console.dir(obj);)

if my query returns an array it will display all properties in input : "show properties'

 

complete code to add in a script editor webpart :see script

 

Querycontenttypesfieds

 

queries samples : 


/_api/web/lists(guid'0E12917B-80F9-4765-8612-22A9AB467123')/items?$select=AssignedTo,Title&$orderby=DueDate desc&$filter=RelaunchDate eq null and Status eq 'In Progress'


/_api/web/getlist('/sites/csc-dev/Lists/myLMist')/fields?$select=Group,InternalName,Title,TypeAsString,Hidden


/_api/web/getlist('/sites/csc-dev/Lists/vdfdfvf')/fields?$select=Group,InternalName,Title,TypeAsString,Hidden&$filter=Hidden eq false and TypeAsString ne 'Computed' and startswith(InternalName, '_') eq false&$orderby=TypeAsString


/_api/web/getlist('/sites/csc-dev/Lists/myLMist')/fields?$select=Group,InternalName,Title,TypeAsString,Hidden


/_api/web/lists(guid'0E12917B-80F9-4765-8612-22A9AB46784E')/items?$select=AssignedTo/EMail,Created,Author/EMail,Body,DueDate,,ID,IsGroup,Modified,Editor/EMail,StartDate,Status,stepName,TaskGroup/EMail,TaskIdentifier,TaskProcessed,TaskProcessedBy/Title,TaskProcessedBy/Id,TaskProcessedBy/EMail,Title,WFFormFieldStepType,WFInstance&$orderby=DueDate desc&$filter=RelaunchDate eq null and Status eq 'In Progress'&$expand=Author,Editor,AssignedTo,TaskProcessedBy,TaskGroup

USER

{
Title: string;
EMail: string;
Id: number;
}

CSOM powershell SSL TSL site

On 23/11/2019

 

Exception calling "ExecuteQuery" with "0" argument(s): "The request was aborted: Could not create SSL/TLS secure channel." SOLVED

Exception lors de l'appel de ExecuteQuery" avec 0" argument(s): La demandea été abandonnée: Impossible de créer un canal sécurisé SSL/TLS." : résolu

How to connect to a SSL/ TSL sharepoint site with CSOM in powershell

Start to call a request with your certificate

 

 
$anUrl = https://mySharepoint

$CertificateThumbprint = "53836D3C35F949959D7E4038D5D39D7B"

$response = Invoke-WebRequest -Verbose -URI $anUrl -CertificateThumbprint $CertificateThumbprint -UseDefaultCredentials -SessionVariable websession -ErrorAction:Stop

 

 

# extract cookies from your response, and isolate wich one is authentication cookie
$cookies = $websession.Cookies.GetCookies($anUrl)
$global:cookieName3= "$($cookies[$i].name)".Trim();
$global:cookieVal3 = "$($cookies[$i].value)".Trim();

 

# get correct certificate in your store
$global:cert = Get-ChildItem -Path cert:\CurrentUser\My | ?{$_.Thumbprint -eq $CertificateThumbprint}
$context987 = New-Object Microsoft.SharePoint.Client.ClientContext($anUrl);
 
# set the security protocol
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor ` [Net.SecurityProtocolType]::Tls11 -bor ` [Net.SecurityProtocolType]::Tls -bor ` [Net.SecurityProtocolType]::Ssl3

 

# add an ExecutingWebRequest event, which will be raised on each Execute query
$context987.add_ExecutingWebRequest({ })

 

# in this ExecutingWebRequest you should add the certificate to yoour request and add the authentification cookie

$request = $EventArgs.WebRequestExecutor.WebRequest

$request.ClientCertificates.Add($global:cert)
$request.CookieContainer = New-Object System.Net.CookieContainer
$c3 = New-Object System.Net.Cookie($global:cookieName3, $global:cookieVal3, "/", $global:cookieDomaine);
$request.CookieContainer.Add($c3);
$context987.Load($context987.web);
$context987.ExecuteQuery();
Write-Host "Title : $($web.Title)"

 

 

to list all your available certificate execute following script

[System.Security.Cryptography.X509Certificates.X509Store]$storeNew-Object System.Security.Cryptography.X509Certificates.X509Store([System.Security.Cryptography.X509Certificates.StoreName]::My, [System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser) # LocalMachine
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly);
$store.Certificates | select Thumbprint, FriendlyName, Subject

Hide Sharepoint Top Nav

On 30/10/2019

Add in your query string fdiedit=1 to show the top vanigation
<style>
#SearchBox{
display: none;
}
#gdocSearchBox {
display: block;
}
#s4-ribbonrow{
display: none;
}
#suiteBarTop{
display: none;
}
#SearchBox{
display: none;
}
 
#DeltaTopNavigation .root.ms-core-listMenu-root.static {
margin-top: 10px;
}
 
#s4-titlerow {
margin-top: 0px;
margin-bottom: 0px;
padding-top: 0px;
padding-bottom: 1px;
height: 20px;
}
.ms-breadcrumb-top{
display: flex;
}
</style>
 
<script type="text/javascript">
 
function showSpStandard() {//show top nav
jq("#suiteBarTop").show();
jq("#s4-ribbonrow").show();
jq("#SearchBox").show();
jq("#DeltaPageStatusBar").show();
jq("#s4-titlerow").show();
jq("#suiteBarTop").show();
jq(".root.ms-core-listMenu-root.static").show();
}
function getUrlVars() {//get query strings
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
 
function fdiShowEdit(){//if query string
var canEdit = getUrlVars()["fdiedit"];
if(canEdit == 1)
showSpStandard();
}
 
_spBodyOnLoadFunctionNames.push("fdiShowEdit");
</script>
You can put this script in a script editor webpart or in master page 

Sharepoint Rest Query List

On 21/09/2019

Query sharepoint list with REST

 

use this end point to query your list http://test/sites/test/_api/Web/Lists/getbytitle('vvv')/items?$select=&$filter= Title eq 'entite du ga 1'

Example : http://test01/sites/test01/_api/Web/Lists/getbytitle('Aliste')/items?$select=Title,ID,Author/Title&$expand=Author&$filter= Title eq 'entite du toto 1'

to order by : &$orderby= Employee asc

to order by : &$orderby= Employee desc

to limit number of items returned : $top 5

to use paging : $skip 5

new paging mode add in your first query  &$skiptoken=Paged=TRUE in your response, you will receive next page query in odata.nextLink as below

Nextlink

/_api/Web/Lists/getbytitle(%27Initiatives%27)/items?%24skiptoken=Paged%3dTRUE%26p_ID%3d266&%24select=Title%2cID&%24orderby=ID+desc&p_ID=268&%24Top=3

 

expand lookup fields : $expand=city&$select=city/Id

 

viewfields : $select= Title, ID

filter : $filter=Title eq 'mon noeud' and ID ne 1

 

Numeric comparisons

  • Lt
  • Le
  • Gt
  • Ge
  • Eq
  • Ne
 

String comparisons

  • startsWith
  • substringof
  • Eq
  • Ne
 

Date and time functions

  • day()
  • month()
  • year()
  • hour()
  • minute()
  • second()

 

 

Querylist 1

 
 

html to query list

 

javascript to query list

 

css to query list

 

base html file

 

Full script to add in an Script Editor webpart

 

script without JQuery

Powershell Csom Paged Caml Query

On 18/09/2019

 


$list = Get-PnPList -Identity $listTitle -ThrowExceptionIfListNotFound

$ctx = Get-PnPContext
$page = $null
$pageNumber = 0;
$rowLimit = 200
Do{
    $stringBuilder = New-Object System.Text.StringBuilder
 
    $stringBuilder.Append("<View Scope='RecursiveAll'>") | Out-Null
    $stringBuilder.Append("<Query><Where></Where>")| Out-Null
    $stringBuilder.Append("<OrderBy><FieldRef Name='ID' Ascending='TRUE' /></OrderBy>")| Out-Null
    $stringBuilder.Append("</Query>")| Out-Null
    $stringBuilder.Append("<ViewFields>")| Out-Null
    $stringBuilder.Append("<FieldRef Name='ID' />")| Out-Null
    $stringBuilder.Append("<FieldRef Name='Title' />")| Out-Null
    $stringBuilder.Append("</ViewFields>")| Out-Null
    $stringBuilder.Append("<RowLimit Paged='TRUE'>$($rowLimit)</RowLimit>")| Out-Null
    $stringBuilder.Append("</View>")| Out-Null
    
    $spqQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
    $spqQuery.ViewXml = $stringBuilder.ToString();
    $spqQuery.ListItemCollectionPosition = $page


    $pageNumber ++;

    $spqQuery.ViewXml = $stringBuilder.ToString();
    $itemki=$list.GetItems($spqQuery); 
    $spqQuery.ListItemCollectionPosition = $itemki.ListItemCollectionPosition

    $ctx.Load($itemki)
    $ctx.ExecuteQuery();


    Write-Host "################## PAGE " $($page.PagingInfo) " #########################"
    Write-Host "processing query results. Recs: $($itemki.Count)"

    $Counter = 0;
    foreach($item in $itemki)
    {
        Write-Host "$($item["ID"]) title pageNumber '$($pageNumber)' : $($item["Title"])"
    }

    $page = $itemki.ListItemCollectionPosition
 }   
 Until($page -eq $null) 


 
get script

Add SPList With CSOM

On 15/08/2019

function AddList()
{param($url0, $title)
 
$context0 = New-Object Microsoft.SharePoint.Client.ClientContext($url0);
 
$context0.AuthenticationMode = [Microsoft.SharePoint.Client.ClientAuthenticationMode]::FormsAuthentication
$credentials0 = New-Object Microsoft.SharePoint.Client.FormsAuthenticationLoginInfo("d03305", $mypsw);
$context0.FormsAuthenticationLoginInfo = $credentials0;
 
[Microsoft.SharePoint.Client.Web]$web0 = $context0.Web;
 
 
 
$context0.Load($web0)
$context0.Load($web0.ListTemplates)
$context0.ExecuteQuery()
 
$template = $web0.ListTemplates | Where-Object {$_.Name -eq "Fiche de conformité"}
$template.Name
 
#check if list exists
$list = $null;
try
{
$list = $web0.GetList("$($web0.ServerRelativeUrl.TrimEnd("/"))/$($title)");
$context0.Load($list);
$context0.ExecuteQuery();
}
catch
{
$list = $null;
}
if($list -eq $null)
{
Write-Host "list is null"
#creation de la liste
$ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListInfo.Title = $title
[System.Int32]$lstId = 100#$template.ListTemplateTypeKind;
$ListInfo.TemplateType = $lstId;
$List1 = $web0.Lists.Add($ListInfo);
<#
$List1.Description = "$($title) GED Corporate";
$List1.Update()
#>
$context0.ExecuteQuery()
 
}
else
{
Write-Host "list is not null"
}
 
$list.Title;
 
$context0.Dispose();
$context0 = $null;
}