- Home
- Blog
Blog
On 24/10/2023
How to prevent recursives update on trigger "When an item is created or modified"
add this in trigger settings, set your email (a service account) thaht will not launch the trigger
@not(equals(toLower(triggerOutputs()?['body/Author/Email']), 'service_account@test1.com'))
so with this settings you can perform an update in your flow without recursive trigger
On 20/10/2023
How to join datas from Excel Tables
Create 2 Tables with a common column
Name your table
Save Your table
Merge tables with a leftOuterJoin
Keep only required columns
Remove dupplicates
Results
SPFX React Override Native CSS
On 12/07/2023
How to override native SharePoint css in SPFX react webparts
:global .webPartContainer{
display: none;
}
Csom Context Sharepoint ClientContext
On 23/05/2023
c# Connect to Sharepoint with ClientContext appId and certificat ThumbPrint
using Microsoft.Identity.Client;
using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace MY.PNP.Powershell.EXT.CSOM
{
public class CsomContext : IDisposable
{
public ClientContext _clientContext;
public ClientRuntimeContext _context;
private async Task GetAccessToken(string tenantName, string clientId, string thumbprint)
{
var certificate = GetCert(thumbprint);
var authority = $"https://login.microsoftonline.com/{tenantName}.onmicrosoft.com/";
var azureApp = ConfidentialClientApplicationBuilder.Create(clientId)
.WithAuthority(authority)
.WithCertificate(certificate)
.Build();
var scopes = new string[] { $"https://{tenantName}.sharepoint.com/.default" };
var authResult = await azureApp.AcquireTokenForClient(scopes).ExecuteAsync();
return authResult.AccessToken;
}
public async Task CallClientObjectModel(string tenantName, string url, string clientId, string thumbprint)
{
var token = await GetAccessToken(tenantName, clientId, thumbprint);
var siteUrl = url;//;$"https://{tenantName}.sharepoint.com";
var context = new ClientContext(siteUrl);
context.ExecutingWebRequest += (s, e) =>
{
e.WebRequestExecutor.RequestHeaders["Authorization"] =
"Bearer " + token;
};
var web = context.Web;
context.Load(web);
context.ExecuteQuery();
Console.WriteLine(web.Title);
Console.WriteLine(web.Url);
_context = web.Context;
_clientContext = context;
}
private X509Certificate2 GetCert(string thumbprint)
{
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint,
// Replace below with your cert's thumbprint
thumbprint,
false);
X509Certificate2 cert = null;
// Get the first cert with the thumbprint
if (certCollection.Count > 0)
{
cert = certCollection[0];
// Use certificate
Console.WriteLine(cert.FriendlyName);
}
certStore.Close();
return cert;
}
public void Dispose()
{
if (_context != null)
_context.Dispose();
if (_clientContext != null)
_clientContext.Dispose();
}
}
}
Connect Graph API GraphServiceClient With Certificate thumbprint
On 10/05/2023
using Microsoft.Graph;
using Microsoft.Identity.Client;
using System;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Azure.Identity;
using System.Reflection.Metadata.Ecma335;
using Microsoft.Graph.Models;
public class ClientCredentialsAuthProvider
{
private readonly IConfidentialClientApplication msalClient;
private readonly string[] scopes;
protected GraphServiceClient _graphClient;
public ClientCredentialsAuthProvider()
{
try
{
string appId = "922b7a94-268f-4ac0-ad5e-4d44fe4429cf";
string tenantId = "3533ab30-c2f0-48fd-b4c5-f5dc6ca77ec3";
string thumbprint = "AD120A05FF3AAC9A71A6DD71530E96306C29B395 ";// "AD120A05FF3AAC9A71A6DD71530E96306C29B395";
var scopes = new[] { "https://graph.microsoft.com/.default" };//"https://graph.microsoft.com/.default", "User.Read"
// Values from app registration
var clientId = appId;
var clientCertificate = GetCert(thumbprint);
// using Azure.Identity;
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientCertCredential = new ClientCertificateCredential(
tenantId, clientId, clientCertificate, options);
this._graphClient = new GraphServiceClient(clientCertCredential, scopes);
}
catch (Exception ex)
{
throw ex;
}
}
public async Task GetUserByMail(string mail)
{
try
{
var result = await this._graphClient.Users.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Select = new string[] { "displayName", "id", "mail" };
requestConfiguration.QueryParameters.Filter = string.Format("mail eq '{0}'", mail);
requestConfiguration.QueryParameters.Orderby = new string[] { "displayName" };
requestConfiguration.QueryParameters.Count = true;
requestConfiguration.Headers.Add("ConsistencyLevel", "eventual");
});
if (result.OdataCount == 1)
{
Microsoft.Graph.Models.User user = result.Value[0];
return user;
}
return null;
}
catch (Exception ex)
{
throw;
}
}
public async Task CreateTeams(string teamsName, string teamsDescription, string ownerId)
{
try
{
GraphServiceClient graphClient = null;
string getUser = string.Format("https://graph.microsoft.com/v1.0/users('{0}')", ownerId);
var requestBody = new Team
{
DisplayName = teamsName,
Description = teamsDescription,
Members = new List
{
new ConversationMember
{
OdataType = "#microsoft.graph.aadUserConversationMember",
Roles = new List
{
"owner",
}
,
AdditionalData = new Dictionary
{
{
"user@odata.bind" , getUser
},
},
},
},
AdditionalData = new Dictionary
{
{
"template@odata.bind" , "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
}
}
};
var result = await this._graphClient.Teams.PostAsync(requestBody);
return "";
}
catch (Exception ex)
{
throw;
}
}
private X509Certificate2 GetCert(string thumbprint)
{
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint,
// Replace below with your cert's thumbprint
thumbprint,
false);
X509Certificate2 cert = null;
// Get the first cert with the thumbprint
if (certCollection.Count > 0)
{
cert = certCollection[0];
// Use certificate
Console.WriteLine(cert.FriendlyName);
}
certStore.Close();
return cert;
}
}
JSON Formatting Show File Size
On 03/05/2023
Show File size in kilo bytes in sharepoint list
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"attributes": {
},
"style": {
"flex-directon": "row",
"justify-content": "left",
"align-items": "center",
"flex-wrap": "nowrap"
},
"children": [
{
"elmType": "span",
"txtContent": "=[$File_x0020_Size]/1000 + ' kbytes'"
}
]
}
PowerAutomate history Unexpected Error Unable To Fetch
On 21/04/2023
PowerAutomate history - Unexpected error. Unable to fetch
I my case to solve this issue, i press "ctrl + R" then "ctrl + F5", then i should wait a few minutes before opening les boxes and it's ok
If this error persists, you can download, full history in a csv file that you can analize, yes you need to rean JSON code and Sharepoint http requests
in your flow error message copy le run ID to seek it in your csv file in url
https://make.powerautomate.com/environments/Default-d035406542/solutions/b03b5e55-c8d9-ed11-a7c7-000d3a2726a5/flows/21fb6dc1-0412-3540684-f0a6881c120f/runs/08585210145218379217946437495CU195
JSON Formatting Is Member of Group
On 11/04/2023
show button if user if member of a sharepoint group
Compaire now + 30 days
@now>[$testDate]+2592000000
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"style": {
"flex-directon": "row",
"justify-content": "left",
"align-items": "center",
"flex-wrap": "nowrap"
},
"children": [
{
"elmType": "div",
"style": {
"display": "=if(([$ItemStatus] == 'Pending' || [$ItemStatus] == '') && ([$PermMask]=='0x1b03c5b1bff' || [$PermMask]=='0x7ffffffffffbffff'), 'inherit','none')",
"flex-directon": "row",
"justify-content": "left",
"align-items": "center",
"flex-wrap": "wrap"
},
"children": [
{
"elmType": "button",
"customRowAction": {
"action": "setValue",
"actionInput": {
"ItemStatus": "Approved",
"ApprovalActionBy": "@me"
}
},
"attributes": {
"class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
},
"style": {
"border": "none",
"display": "=if([$PermMask]>='0x1b03c5b1bff', 'inherit','none')",
"background-color": "transparent",
"cursor": "pointer",
"display": "flex",
"flex-directon": "row",
"justify-content": "left",
"align-items": "center",
"flex-wrap": "wrap"
},
"children": [
{
"elmType": "span",
"attributes": {
"iconName": "SkypeCircleCheck"
},
"style": {
"padding": "4px"
}
},
{
"elmType": "span",
"txtContent": "Approve",
"style": {
"word-break": "keep-all"
}
}
]
},
{
"elmType": "button",
"customRowAction": {
"action": "setValue",
"actionInput": {
"ItemStatus": "Rejected",
"ApprovalActionBy": "@me"
}
},
"attributes": {
"class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
},
"style": {
"border": "none",
"display": "=if(([$ItemStatus] == 'Pending' || [$ItemStatus] == ''), 'inherit','none')",
"background-color": "transparent",
"cursor": "pointer",
"display": "flex",
"flex-directon": "row",
"justify-content": "left",
"align-items": "center",
"flex-wrap": "wrap"
},
"children": [
{
"elmType": "span",
"attributes": {
"iconName": "Blocked"
},
"style": {
"padding": "4px"
}
},
{
"elmType": "span",
"txtContent": "Reject",
"style": {
"word-break": "keep-all"
}
}
]
}
]
},
{
"elmType": "div",
"children": [
{
"elmType": "span",
"txtContent": "='This item is ' + toLowerCase([$ItemStatus])",
"style": {
"display": "=if([$ItemStatus] == 'Pending' ||[$ItemStatus] == '' , 'none','inherit')",
"padding-left": "5px",
"word-break": "keep-all"
}
}
]
}
]
}