Skip to content

Instantly share code, notes, and snippets.

@ktskumar
Created June 6, 2021 05:29
Show Gist options
  • Save ktskumar/c0a50aaefbe3246888b122f847bf88ff to your computer and use it in GitHub Desktop.
Save ktskumar/c0a50aaefbe3246888b122f847bf88ff to your computer and use it in GitHub Desktop.
Retrieves the Flow instances associated to the SharePoint List using REST API
/* **** RUN THIS SNIPPET in Browser Developer Console to see the output **** */
// POST request Call
function RestRequest(url, params) {
var req = new XMLHttpRequest();
return new Promise(function(resolve, reject) {
req.onreadystatechange = function() {
if (req.readyState != 4) // Loaded
return;
if (req.status >= 200 && req.status < 300) {
resolve(req);
} else {
reject({
status: req.status,
statusText: req.statusText
});
}
};
// Prepend web URL to url and remove duplicated slashes.
var webBasedUrl = (_spPageContextInfo.webServerRelativeUrl + "//" + url).replace(/\/{2,}/, "/");
req.open("POST", webBasedUrl, true);
req.setRequestHeader("Content-Type", "application/json;odata=verbose");
req.setRequestHeader("ACCEPT", "application/json;odata=verbose");
req.setRequestHeader("x-requestdigest", _spPageContextInfo.formDigestValue);
req.send(params ? JSON.stringify(params) : void 0);
});
}
//Sends the post request and retrieves the Flow instances associated to SharePoint
RestRequest("/_api/web/GetList(@a1)/SyncFlowInstances?@a1='/sites/TeamSite/Lists/Clients'", null).then(function(resp) {
var output = JSON.parse(resp.response);
var flowinstances = JSON.parse(output.d.SynchronizationData).value;
for (var i = 0; i < flowinstances.length; i++) {
console.log('Name: ' + flowinstances[i].name + "\r\nDisplayName: " + flowinstances[i].properties.displayName + "\r\nEnvironment Name: " + flowinstances[i].properties.environment.name + "\r\nModified: " + flowinstances[i].properties.lastModifiedTime);
}
});
/* **** OUTPUT ****
Name: 15f8b670-f050-4c2b-a6b8-b906e569911f
DisplayName: Send a customized email when a new SharePoint list item is added
Environment Name: Default-6a0*****-****-****-****-*****69d1115
Modified: 2021-06-06T01:35:58.7551102Z
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment