diff --git a/src/clients/Elsa.Api.Client/Extensions/ActivityExtensions.cs b/src/clients/Elsa.Api.Client/Extensions/ActivityExtensions.cs index 2663488ad..6ae48eab8 100644 --- a/src/clients/Elsa.Api.Client/Extensions/ActivityExtensions.cs +++ b/src/clients/Elsa.Api.Client/Extensions/ActivityExtensions.cs @@ -145,11 +145,26 @@ public static class ActivityExtensions /// Sets the root activity in the specified activity. /// public static void SetRoot(this JsonObject container, JsonObject root) => container.SetProperty(root, "root"); - + /// /// Gets the root activity in the specified activity. /// - public static string? GetWorkflowDefinitionId(this JsonObject activity) => activity.GetProperty("workflowDefinitionId"); + public static string? GetWorkflowDefinitionId(this JsonObject activity) + { + // Determine if this activity represents a workflow definition activity based on the presence of the following properties. + var workflowDefinitionIdNode = activity.GetProperty("workflowDefinitionId"); + var workflowDefinitionVersionId = activity.GetProperty("workflowDefinitionVersionId"); + var latestAvailablePublishedVersion = activity.GetProperty("latestAvailablePublishedVersion"); + var latestAvailablePublishedVersionId = activity.GetProperty("latestAvailablePublishedVersionId"); + + if (workflowDefinitionIdNode == null || workflowDefinitionVersionId == null || latestAvailablePublishedVersion == null || latestAvailablePublishedVersionId == null) + return null; // Not a workflow definition activity. + + if (workflowDefinitionIdNode is JsonValue value) + return value.ToString(); + + return null; // Not a workflow definition activity. + } /// /// Determines whether the given activity is a workflow definition activity. @@ -157,7 +172,7 @@ public static class ActivityExtensions /// The JsonObject representing the activity. /// Returns true if the activity is a workflow definition activity; otherwise, false. public static bool GetIsWorkflowDefinitionActivity(this JsonObject activity) => activity.ContainsKey("workflowDefinitionId") && activity.ContainsKey("workflowDefinitionVersionId"); - + /// /// Gets a value indicating whether the specified activity can trigger the workflow. ///