Skip to content

Commit

Permalink
Update ContentUpdateTask, add SetCorrelationId function (#10928)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzx86 authored Apr 22, 2024
1 parent 0140e68 commit 3b4866e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ public async override Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecuti
await ContentManager.SaveDraftAsync(contentItem);
}

workflowContext.CorrelationId = contentItem.ContentItemId;
if (string.IsNullOrEmpty(workflowContext.CorrelationId))
{
workflowContext.CorrelationId = contentItem.ContentItemId;
}

workflowContext.Properties[ContentEventConstants.ContentItemInputKey] = contentItem;
workflowContext.LastResult = contentItem;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecuti
var contentItem = (await ContentManager.GetAsync(contentItemId, VersionOptions.Latest))
?? throw new InvalidOperationException($"The '{nameof(RetrieveContentTask)}' failed to retrieve the content item.");

workflowContext.CorrelationId = contentItem.ContentItemId;
if (string.IsNullOrEmpty(workflowContext.CorrelationId))
{
workflowContext.CorrelationId = contentItem.ContentItemId;
}

workflowContext.Properties[ContentEventConstants.ContentItemInputKey] = contentItem;
workflowContext.LastResult = contentItem;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ public async override Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecuti
}
}

workflowContext.CorrelationId = contentItem.ContentItemId;
if (string.IsNullOrEmpty(workflowContext.CorrelationId))
{
workflowContext.CorrelationId = contentItem.ContentItemId;
}

workflowContext.Properties[ContentEventConstants.ContentItemInputKey] = contentItem;
workflowContext.LastResult = contentItem;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class WorkflowMethodsProvider : IGlobalMethodProvider
private readonly GlobalMethod _setPropertyMethod;
private readonly GlobalMethod _resultMethod;
private readonly GlobalMethod _correlationIdMethod;
private readonly GlobalMethod _setCorrelationIdMethod;

public WorkflowMethodsProvider(WorkflowExecutionContext workflowContext)
{
Expand Down Expand Up @@ -65,11 +66,18 @@ public WorkflowMethodsProvider(WorkflowExecutionContext workflowContext)
Name = "correlationId",
Method = serviceProvider => (Func<string>)(() => workflowContext.Workflow.CorrelationId),
};

_setCorrelationIdMethod = new GlobalMethod
{
Name = "setCorrelationId",
Method = serviceProvider => ((string correlationId) => workflowContext.CorrelationId = correlationId),
};

}

public IEnumerable<GlobalMethod> GetMethods()
{
return new[] { _workflowMethod, _workflowIdMethod, _inputMethod, _outputMethod, _propertyMethod, _resultMethod, _correlationIdMethod, _setPropertyMethod };
return [_workflowMethod, _workflowIdMethod, _inputMethod, _outputMethod, _propertyMethod, _resultMethod, _correlationIdMethod, _setPropertyMethod, _setCorrelationIdMethod];
}
}
}
1 change: 1 addition & 0 deletions src/docs/reference/modules/Scripting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ The following JavaScript functions are available by default to any workflow acti
| `property(name: String): Any` | Returns the property value with the specified name. Properties are a dictionary that workflow activities can read and write information from and to. |
| `lastResult(): Any` | Returns the value that the previous activity provided, if any. |
| `correlationId(): String` | Returns the correlation value of the workflow instance. |
| `setCorrelationId(id:string): void` | Set the correlation value of the workflow instance. |
| `signalUrl(signal: String): String` | Returns workflow trigger URL with a protected SAS token into which the specified signal name is encoded. Use this to generate URLs that can be shared with trusted parties to trigger the current workflow if it is blocked on the Signal activity that is configured with the same signal name. |
| `setOutcome(outcome: String): void` | Adds the provided outcome to the list of outcomes of the current activity |
| `createWorkflowToken(workflowTypeId: String, activityId: String, expiresInDays: Integer): String` | Generates a workflow SAS token for the specidied workflowTypeid, activityId. You can also set the expiration date in number of days. |
1 change: 1 addition & 0 deletions src/docs/reference/modules/Workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ The following JavaScript functions are available by default to any activity that
| `log` | Output logs according to the specified log level. Allowed log levels : `'Trace','Debug','Information','Warning','Error','Critical','None'` | `log(level: string, text: string, param: object): void` |
| `lastResult` | Returns the value that the previous activity provided, if any. | `lastResult(): any` |
| `correlationId` | Returns the correlation value of the workflow instance. | `correlationId(): string` |
| `setCorrelationId` | Set the correlation value of the workflow instance. | `setCorrelationId(id:string): void` |
| `signalUrl` | Returns workflow trigger URL with a protected SAS token into which the specified signal name is encoded. Use this to generate URLs that can be shared with trusted parties to trigger the current workflow if it is blocked on the Signal activity that is configured with the same signal name. | `signalUrl(signal: string): string` |

#### JavaScript Functions in HTTP activities
Expand Down
9 changes: 9 additions & 0 deletions src/docs/releases/1.9.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ Added new extensions to make registering custom deployment step easier:

The method `Task TriggerEventAsync(string name, IDictionary<string, object> input = null, string correlationId = null, bool isExclusive = false, bool isAlwaysCorrelated = false)`
was changed to return `Task<IEnumerable<WorkflowExecutionContext>>` instead.

#### CorrelationId

**Breaking change:**
`CreateContentTask`, `RetrieveContentTask`, and `UpdateContentTask`, in previous versions, the workflow's CorrelationId was updated each time with the ContentItemId of the current content item;
Now, the CorrelationId value will only be updated if the current workflow's CorrelationId is empty.

Also added a workflow-scoped script function `setCorrelationId(id:string): void`, that you can use to update the workflow's CorrelationId.


### GraphQL Module

Expand Down

0 comments on commit 3b4866e

Please sign in to comment.