Created
October 31, 2018 19:29
-
-
Save AshV/b0eb8aef725a8c6670d3c20f80b54029 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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