Blog

PowerAutomate Try Catch

PowerAutomate Try Catch

On 06/12/2022

Try catch in power automate

Try

 


2 jsonerror

 

    
        {
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "name": {
                "type": "string"
            },
            "startTime": {
                "type": "string"
            },
            "endTime": {
                "type": "string"
            },
            "trackingId": {
                "type": "string"
            },
            "clientTrackingId": {
                "type": "string"
            },
            "clientKeywords": {
                "type": "array",
                "items": {
                    "type": "string"
                }
            },
            "code": {
                "type": "string"
            },
            "status": {
                "type": "string"
            },
            "error": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string"
                    },
                    "message": {
                        "type": "string"
                    }
                }
            }
        },
        "required": [
            "name",
            "startTime",
            "endTime",
            "trackingId",
            "clientTrackingId",
            "clientKeywords",
            "code",
            "status",
            "error"
        ]
    }
}
    

 

3 analysejson

 

    
        {
            "type": "object",
            "properties": {
                "id": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "type": {
                    "type": "string"
                },
                "location": {
                    "type": "string"
                },
                "tags": {
                    "type": "object",
                    "properties": {
                        "flowDisplayName": {
                            "type": "string"
                        },
                        "environmentName": {
                            "type": "string"
                        },
                        "logicAppName": {
                            "type": "string"
                        },
                        "environmentWorkflowId": {
                            "type": "string"
                        },
                        "xrmWorkflowId": {
                            "type": "string"
                        },
                        "environmentFlowSuspensionReason": {
                            "type": "string"
                        },
                        "sharingType": {
                            "type": "string"
                        }
                    }
                },
                "run": {
                    "type": "object",
                    "properties": {
                        "id": {
                            "type": "string"
                        },
                        "name": {
                            "type": "string"
                        },
                        "type": {
                            "type": "string"
                        }
                    }
                }
            }
        }

    
        concat('https://emea.flow.microsoft.com/manage/environments/', body('Analyser_JSON')?['tags']?['environmentName'], '/flows/', body('Analyser_JSON')?['name'], '/runs/', body('Analyser_JSON')?['run']?['name'])           
    

 

4 linkhisto


 

    
        a href="@{outputs('LinkToWfHisto')}​​​​​">​​​​​@{workflow()?['tags']?['flowDisplayName']} a
    

 


 

5 aref

PowerAutomate Date Format

On 30/09/2022

formatDateTime('2009-06-15T13:45:30', 'M/dd/yyyy h:mm tt')  6/15/2009 1:45 PM

formatDateTime('2009-06-15T13:45:30', 'dd/MM/yyyy') 15/06/2009

formatDateTime('2009-06-15T13:45:30', 'd/M/yyyy') 15/6/2009

formatDateTime('2009-12-15T13:45:30', 'dddd/MMMM/yyyy') Tuesday/December/2009

formatDateTime('2009-12-15T13:45:30', 'ddd/MMM/yyyy') Tue/Dec/2009

PowerAutomate Functions

On 21/04/2022

Concat

concat(outputs('Compose'),'test')

 

Get user mail in REST results

items('Appliquer_à_chacun')?['MyUser']?['EMail']

 

Add 10 Days

addDays(utcNow(),10)

 

Get JSON data

 

body('parameterJSON')?['Relaunch1nbDays']
body('myGet')?['value']

 

 

Get variable value

variables('RelaunchDate1')

 

Check data is empty

if(empty(variables('userMail')), null, variables('userMail'))

 

Date formatting

formatDateTime(your-value, 'dd/MM/yyyy hh:mm tt')

image base64 to <img>

 


Get_file_content_using_path_2')['$content']  //the $ is important
<img class="logo" src="data:image/jpeg;base64, @{body('Get_file_content_using_path_2')['$content']}" alt="My Image" />

 

Json Formatting Edit Button

On 21/04/2022

Add an edit button, in field json formatting


{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "children": [
        {
            "elmType": "span",
            "style": {
                "padding-right": "8px"
            },
            "txtContent": "@currentField.title"
        },
        {
            "elmType": "a",
            "style": {
                "text-decoration": "none"
            },
            "attributes": {
                "iconName": "Edit",
                "class": "sp-field-quickActions",
				"target": "_blank",
                "href": {
                    "operator": "+",
                    "operands": ["www.source=portal&screenColor=rgba%280%2C+176%2C+240%2C+1%29&skipAppMetadata=true&ID=",
                        "[$ID]"
                    ]
                }
            }
        }
    ]
}

Power Automate Check User Exists

On 24/01/2022

Checkuser1

Checkuser2

 


/_api/web/ensureuser
content-type application/json; odata=verbose

{'logonName': '@{variables('userMailToCheck')}'}
@{outputs('Send_an_HTTP_request_to_SharePoint')['statusCode']}


How to resolve the 5000 item limit

On 24/01/2022

     var firstItems = listLocation.web.getList(listLocation.listUri).items.select("ID").top(1).orderBy("Id").get();
     var lastItems = listLocation.web.getList(listLocation.listUri).items.select("ID").top(1).orderBy("Id", false).get(); 

    if (firstItems.length === 1 && lastItems.length === 1) {
      const firstId: number = firstItems[0].ID;
      const lastId: number = lastItems[0].ID;
      let startId = firstId;
      let endId = firstId + 5000;
      do {
        let mySites: ISite[] = await listLocation.web.getList(listLocation.listUri).items

          .select("ID", "Title", "Url")
          .filter(`Id ge ${startId} and Id lt ${endId} and ProprietairesPeople/Id eq ${userId}`)
          .expand('ProprietairesPeople')
          .orderBy("Title")
          .top(5000)
          .getAll(); 

          allMySites.push(...mySites);
          startId = startId + 5000;
          endId = endId + 5000;
      }
      while (endId < lastId);
    }
    return allMySites;

Add User To Group With Rest

On 20/09/2021

Add User To Sharepoint Group With Rest

 


var fdi = fdi || {};

fdi.post = function(request, data, urlWeb, retFunction, expecedcode=200, odata="verbose"){
    var url = _spPageContextInfo.webAbsoluteUrl + "/_api/contextinfo?&select=FormDigestValue";
	var xhr = new XMLHttpRequest();
	xhr.open('POST', url, true);
	xhr.setRequestHeader("Accept", "application/json; odata=nometadata");
	xhr.onload = function () {
		if (xhr.status === 200) {
			console.log(url + " : success");
			var d = JSON.parse(xhr.responseText);
            console.dir(d.FormDigestValue);

            var viewXml =  "" +
                    "" +
                    "" +
                    "" +
                    "";
            
            var req = { "query" :{"__metadata": { "type": "SP.CamlQuery" }, "ViewXml": viewXml}};
            var xhrPOST = new XMLHttpRequest();
            var reqUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups(5)/users";
            //debugger;
            xhrPOST.open('POST', reqUrl, true);
            xhrPOST.setRequestHeader("Accept", "application/json; odata=" + odata);
            xhrPOST.setRequestHeader("content-type", "application/json; odata=" + odata);
            xhrPOST.setRequestHeader("X-RequestDigest", d.FormDigestValue);

            console.log("onload");
            xhrPOST.onload = function () {
                
            console.log("onload ok");
                console.dir(JSON.parse(xhrPOST.responseText));
            }
			
			var metadata = {  
    __metadata: {  
        'type': 'SP.User'  
    },  
    LoginName: 'i:0#.f|membership|fred.ddiet@test.com'  
};  JSON.stringify(metadata)
            xhrPOST.send(JSON.stringify(metadata));
            console.log("sent");
		}
		else {
			console.log("error");
			console.log(xhr.status);
			console.dir(xhr);
			console.dir(xhr.responseText);			
		}
	};
    xhr.send();
};

fdi.post();

PowerAutomate Add User To Group

On 19/09/2021

Powerautomate add user to sharepoint group

Ajouter un utilisateur dans un groupe sharepoint en REST avec powerautomate

{"__metadata":{"type":"SP.User"},"LoginName":"i:0#.f|membership|@{variables('emailToAdd')}"}
{
  "siteUrl": "https://vvvvvvvvvvvvvvv.com",
  "Accept": "Accept",
  "ApplicationJson": "application/json; odata=verbose",
  "ContentType": "content-type"
}

 

Getassociatedmembers

 

Addusertogroup