Skip to content

Commit e771b97

Browse files
author
ecfan
committed
Draft
1 parent 5aa4102 commit e771b97

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

articles/logic-apps/add-run-csharp-scripts.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,34 @@ This guide shows how to add the action in your workflow and add the C# script co
3939

4040
## Considerations
4141

42-
- The Azure portal saves your script as a .csx file in the same folder as your **workflow.json** file, which stores the JSON definition for your workflow, and deploys the file to your logic app resource along with the workflow definition. Azure Logic Apps compiles this file to make the script ready for execution.
42+
- The Azure portal saves your script as a C# script file (.csx) in the same folder as your **workflow.json** file, which stores the JSON definition for your workflow, and deploys the file to your logic app resource along with the workflow definition. Azure Logic Apps compiles this file to make the script ready for execution.
4343

44-
You can rename the .csx file for easier management during deployment. However, each time you rename the script, the new version overwrites the previous version.
44+
The .csx file format lets you write less "boilerplate" and focus just on writing a C# function. You can rename the .csx file for easier management during deployment. However, each time you rename the script, the new version overwrites the previous version.
4545

46-
- The script is local to the workflow. To use the same script in other workflows, in the Kudo console, find the script file, open the shortcut menu, and then copy the script to reuse in other workflows.
46+
- The script is local to the workflow. To use the same script in other workflows, [view the script file in the **KuduPlus** console](#view-script-file), and then copy the script to reuse in other workflows.
47+
48+
## Limitations
49+
50+
| Name | Limit | Notes |
51+
|------|-------|-------|
52+
| Script run duration | 10 minutes | If you have scenarios that need longer durations, use the product feedback option to provide more information abour your needs. |
53+
| Output size | 100 MB | Output size depends on the output size limit for actions, which is generally 100 MB.
4754

4855
## Add the Execute CSharp Script Code action
4956

50-
1. In the [Azure portal](https://portal.azure.com), open your Standard workflow in the designer.
57+
1. In the [Azure portal](https://portal.azure.com), open your Standard logic app resource and workflow in the designer.
5158

5259
1. In the designer, [follow these general steps to add the **Inline Code Operations** action named **Execute CSharp Script Code action** to your workflow](create-workflow-with-trigger-or-action.md?tabs=standard#add-action).
5360

54-
1. After the action information pane opens, on the **Parameters** tab, in the **Code File** box, enter your script, for example:
61+
1. After the action information pane opens, on the **Parameters** tab, in the **Code File** box, update the prepopluated sample code with your own script code. Make sure to define the **Run** method and include any necessary assembly references and namespaces at the top of the file.
62+
63+
The **Run** method name is predefined, and your workflow executes only by calling this **Run** method at runtime. Data from your workflow flows into the **Run** method through the parameter that has **WorkflowContext** type. The **WorkflowContext** object not only gives your code access to outputs from the trigger, any preceding actions, and the workflow, you can also use this method to accept a function logger as a parameter and cancellation token. This token is necessary if you have a long-running script that requires graceful termination in case the function host shuts down.
64+
65+
The following example shows the action's **Parameters** tab with the sample script code:
5566

5667
:::image type="content" source="media/add-run-csharp-scripts/action-sample-script.png" alt-text="Screenshot shows Azure portal, Standard workflow designer, Request trigger, Execute CSharp Script Code action with information pane open, and Response action. Information pane shows sample C# script." lightbox="media/add-run-csharp-scripts/action-sample-script.png":::
5768

58-
This example continues with the following sample script code:
69+
The following example shows the sample script code:
5970

6071
```csharp
6172
// Add the required libraries.
@@ -76,7 +87,7 @@ This guide shows how to add the action in your workflow and add the C# script co
7687
{
7788
var triggerOutputs = (await context.GetTriggerResults().ConfigureAwait(false)).Outputs;
7889

79-
//// Dereference the 'name' property from the trigger payload.
90+
//// Dereferences the 'name' property from the trigger payload.
8091
var name = triggerOutputs?["body"]?["name"]?.ToString();
8192

8293
//// To get the action outputs from a preceding action, you can uncomment and use the following code.
@@ -98,18 +109,32 @@ This guide shows how to add the action in your workflow and add the C# script co
98109
public string Message {get; set;}
99110
}
100111
```
101-
112+
113+
For more information, see the following documentation:
114+
115+
- ["#r" - Reference external assemblies](/azure/azure-functions/functions-reference-csharp?tabs=functionsv2%2Cfixed-delay%2Cazure-cli#referencing-external-assemblies)
116+
- []
102117

103118
1. When you're done, save your workflow.
104119

120+
<a name="view-script-file"></a>
121+
105122
## View the script file
106123

124+
To find and view the C# script file (.csx), follow these steps:
125+
126+
1. In the [Azure portal](https://portal.azure.com), open your Standard logic app resource that has the workflow you want.
107127

128+
1. On the logic app resource menu, under **Development Tools**, select **Advanced Tools**.
108129

109-
## How scripting works in this scenario
130+
1. On the **Advanced Tools** page, select **Go**, which opens the **KuduPlus** console.
110131

111-
The .csx format allows you to write less "boilerplate" and focus on writing just a C# function. Instead of wrapping everything in a namespace and class, just define a Run method. Include any assembly references and namespaces at the beginning of the file as usual. The name of this method is predefined, and your workflow can run only invoke this Run method at runtime.
132+
1. Open the **Debug console** menu, and select **CMD**.
112133

113-
Data from your workflow flows into your Run method through parameter of WorkflowContext type. In addition to the workflow context, you can also have this method take function logger as a parameter and a cancellation tokens (needed if your script is long running and needs to be gracefully terminate in case of Function Host is shutting down).
134+
1. Browse to the following folder location, which contains the .csx file: **site/wwwroot/{workflow-name}**
135+
136+
1. Next to the file name, select **Edit** to open and view the file.
114137

115138
## Related content
139+
140+
[Add and run JavaScript code snippets](add-run-javascript-code-snippets.md)

articles/logic-apps/logic-apps-add-run-inline-code.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ The following table has more information about these properties:
232232
| `actions` | Object collection | The result objects from any preceding actions that run before your code snippet runs. Each object has a *key-value* pair where the key is the action name, and the value is equivalent to the result from calling the [actions() function](workflow-definition-language-functions-reference.md#actions) with the `@actions('<action-name>')` expression. <br><br>The action's name uses the same action name that appears in the underlying workflow definition, which replaces spaces (**" "**) in the action name with underscores (**\_**). This object collection provides access to the action's property values from the current workflow instance run. |
233233
| `trigger` | Object | The result object from the trigger where the result is the equivalent to calling the [trigger() function](workflow-definition-language-functions-reference.md#trigger). This object provides access to trigger's property values from the current workflow instance run. |
234234
| `workflow` | Object | The workflow object that is the equivalent to calling the [workflow() function](workflow-definition-language-functions-reference.md#workflow). This object provides access to the property values, such as the workflow name, run ID, and so on, from the current workflow instance run. |
235-
||||
236235

237236
In this article's example, the `workflowContext` JSON object might have the following sample properties and values from the Outlook trigger:
238237

1.69 KB
Loading

0 commit comments

Comments
 (0)