Skip to content

Instantly share code, notes, and snippets.

@AshV
Created October 31, 2018 19:29
Show Gist options
  • Save AshV/b0eb8aef725a8c6670d3c20f80b54029 to your computer and use it in GitHub Desktop.
Save AshV/b0eb8aef725a8c6670d3c20f80b54029 to your computer and use it in GitHub Desktop.
Xrm.WebApi.retrieveRecord(
"msdyncrm_customerjourney",
"945a02a0-b2db-e811-a967-000d3af29269",
"$select=msdyncrm_workflowdefinition").then(
function (result) {
debugger;
console.log(result);
var workflowdefinition = JSON.parse(result.msdyncrm_workflowdefinition);
// Retrieve nodes related to provided component.
var emails = rootActivityFilter(workflowdefinition, "Email");
var segemnts = rootActivityFilter(workflowdefinition, "Segment");
var events = rootActivityFilter(workflowdefinition, "Event");
// To get all the record's GUID & metadata use .toArray()
var emailRecords = emails.where(x => x[0].ItemId != null).toArray();
// If you want just number of records .count() can be used
var eventCount = events.where(x => x[0].ItemId != null).count();
},
function (error) {
console.log(error.message);
}
);
// funtion to filter out only data node for provided element
function rootActivityFilter(workflowdefinition, element) {
return Enumerable
.from(workflowdefinition)
.where(w => w.ActivityTypeId == element)
.select(s => s.Properties.Items);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment