> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# NSWorkflowAgent

> Workflow data services.

Workflow data services.

## Constructors

### NSWorkflowAgent()

```crmscript theme={null}
NSWorkflowAgent
```

Initializes a new instance of the NSWorkflowAgent class.

## Methods

## CreateDefaultEmailFlow()

Loading default values into a new NSEmailFlow
NetServer calculates default values (e.g. Country) on the entity, which is required when creating/storing a new instance

```crmscript theme={null}
NSEmailFlow CreateDefaultEmailFlow()
```

**Returns:** [CRMScript.NetServer.NSEmailFlow](CRMScript.NetServer.NSEmailFlow) - New NSEmailFlow with default values.

**Example:**

```crmscript theme={null}
NSWorkflowAgent thing;
NSEmailFlow emailFlow = thing.CreateDefaultEmailFlow();
```

## SaveEmailFlow(NSEmailFlow)

Updates the existing NSEmailFlow or creates a new NSEmailFlow if the id parameter is empty

```crmscript theme={null}
NSEmailFlow SaveEmailFlow(NSEmailFlow emailFlow)
```

**Returns:** [CRMScript.NetServer.NSEmailFlow](CRMScript.NetServer.NSEmailFlow) - New or updated NSEmailFlow

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
NSEmailFlow emailFlow;
NSEmailFlow res = agent.SaveEmailFlow(emailFlow);
```

## DeleteEmailFlow(Integer)

Deletes the NSEmailFlow

```crmscript theme={null}
void DeleteEmailFlow(Integer emailFlowId)
```

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer emailFlowId;
agent.DeleteEmailFlow(emailFlowId);
```

## CreateDefaultWorkflowEvent()

Loading default values into a new NSWorkflowEvent
NetServer calculates default values (e.g. Country) on the entity, which is required when creating/storing a new instance

```crmscript theme={null}
NSWorkflowEvent CreateDefaultWorkflowEvent()
```

**Returns:** [CRMScript.NetServer.NSWorkflowEvent](CRMScript.NetServer.NSWorkflowEvent) - New NSWorkflowEvent with default values

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
NSWorkflowEvent event = agent.CreateDefaultWorkflowEvent();
```

## CreateDefaultWorkflowEventResult()

Loading default values into a new NSWorkflowEventResult
NetServer calculates default values (e.g. Country) on the entity, which is required when creating/storing a new instance

```crmscript theme={null}
NSWorkflowEventResult CreateDefaultWorkflowEventResult()
```

**Returns:** [CRMScript.NetServer.NSWorkflowEventResult](CRMScript.NetServer.NSWorkflowEventResult) - New NSWorkflowEventResult with default values

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
NSWorkflowEventResult result = agent.CreateDefaultWorkflowEventResult();
```

## CreateDefaultWorkflowFilter()

Loading default values into a new NSWorkflowFilter
NetServer calculates default values (e.g. Country) on the entity, which is required when creating/storing a new instance

```crmscript theme={null}
NSWorkflowFilter CreateDefaultWorkflowFilter()
```

**Returns:** [CRMScript.NetServer.NSWorkflowFilter](CRMScript.NetServer.NSWorkflowFilter) - New NSWorkflowFilter with default values

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
NSWorkflowFilter filter = agent.CreateDefaultWorkflowFilter();
```

## CreateDefaultWorkflowGoal()

Loading default values into a new NSWorkflowGoal
NetServer calculates default values (e.g. Country) on the entity, which is required when creating/storing a new instance

```crmscript theme={null}
NSWorkflowGoal CreateDefaultWorkflowGoal()
```

**Returns:** [CRMScript.NetServer.NSWorkflowGoal](CRMScript.NetServer.NSWorkflowGoal) - New NSWorkflowGoal with default values

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
NSWorkflowGoal goal = agent.CreateDefaultWorkflowGoal();
```

## SaveWorkflowGoal(NSWorkflowGoal)

Updates the existing NSWorkflowGoal or creates a new NSWorkflowGoal if the id parameter is empty

```crmscript theme={null}
NSWorkflowGoal SaveWorkflowGoal(NSWorkflowGoal workflowGoal)
```

**Returns:** [CRMScript.NetServer.NSWorkflowGoal](CRMScript.NetServer.NSWorkflowGoal) - New or updated NSWorkflowGoal

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
NSWorkflowGoal goal;
NSWorkflowGoal res = agent.SaveWorkflowGoal(goal);
```

## DeleteWorkflowGoal(Integer)

Deletes the NSWorkflowGoal

```crmscript theme={null}
void DeleteWorkflowGoal(Integer workflowGoalId)
```

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer workflowGoalId;
agent.DeleteWorkflowGoal(workflowGoalId);
```

## CreateDefaultWorkflowTrigger()

Loading default values into a new NSWorkflowTrigger
NetServer calculates default values (e.g. Country) on the entity, which is required when creating/storing a new instance

```crmscript theme={null}
NSWorkflowTrigger CreateDefaultWorkflowTrigger()
```

**Returns:** [CRMScript.NetServer.NSWorkflowTrigger](CRMScript.NetServer.NSWorkflowTrigger) - New NSWorkflowTrigger with default values

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
NSWorkflowTrigger trigger = agent.CreateDefaultWorkflowTrigger();
```

## SaveWorkflowTrigger(NSWorkflowTrigger)

Updates the existing NSWorkflowTrigger or creates a new NSWorkflowTrigger if the id parameter is empty

```crmscript theme={null}
NSWorkflowTrigger SaveWorkflowTrigger(NSWorkflowTrigger workflowTrigger)
```

**Returns:** [CRMScript.NetServer.NSWorkflowTrigger](CRMScript.NetServer.NSWorkflowTrigger) - New or updated NSWorkflowTrigger

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
NSWorkflowTrigger trigger;
NSWorkflowTrigger res = agent.SaveWorkflowTrigger(trigger);
```

## DeleteWorkflowTrigger(Integer)

Deletes the NSWorkflowTrigger

```crmscript theme={null}
void DeleteWorkflowTrigger(Integer workflowTriggerId)
```

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer workflowTriggerId;
agent.DeleteWorkflowTrigger(workflowTriggerId);
```

## CreateDefaultWorkflowWaitForAction()

Loading default values into a new NSWorkflowWaitForAction
NetServer calculates default values (e.g. Country) on the entity, which is required when creating/storing a new instance

```crmscript theme={null}
NSWorkflowWaitForAction CreateDefaultWorkflowWaitForAction()
```

**Returns:** [CRMScript.NetServer.NSWorkflowWaitForAction](CRMScript.NetServer.NSWorkflowWaitForAction) - New NSWorkflowWaitForAction with default values

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
NSWorkflowWaitForAction action = agent.CreateDefaultWorkflowWaitForAction();
```

## SaveWorkflowWaitForAction(NSWorkflowWaitForAction)

Updates the existing NSWorkflowWaitForAction or creates a new NSWorkflowWaitForAction if the id parameter is empty

```crmscript theme={null}
NSWorkflowWaitForAction SaveWorkflowWaitForAction(NSWorkflowWaitForAction workflowWaitForAction)
```

**Returns:** [CRMScript.NetServer.NSWorkflowWaitForAction](CRMScript.NetServer.NSWorkflowWaitForAction) - New or updated NSWorkflowWaitForAction

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
NSWorkflowWaitForAction action;
NSWorkflowWaitForAction res = agent.SaveWorkflowWaitForAction(action);
```

## DeleteWorkflowWaitForAction(Integer)

Deletes the NSWorkflowWaitForAction

```crmscript theme={null}
void DeleteWorkflowWaitForAction(Integer workflowWaitForActionId)
```

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer workflowWaitForActionId;
agent.DeleteWorkflowWaitForAction(workflowWaitForActionId);
```

## GetEmailFlow(Integer)

Gets a NSEmailFlow object.

```crmscript theme={null}
NSEmailFlow GetEmailFlow(Integer emailFlowId)
```

**Returns:** [CRMScript.NetServer.NSEmailFlow](CRMScript.NetServer.NSEmailFlow) - NSEmailFlow

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer emailFlowId;
NSEmailFlow flow = agent.GetEmailFlow(emailFlowId);
```

## TryAddPersonsToEmailFlow(Integer,Integer\[])

Try to add a participant to the EmailFlow. Same function available in PersonAgent

```crmscript theme={null}
Bool[] TryAddPersonsToEmailFlow(Integer emailFlowId, Integer[] personIds)
```

**Returns:** [CRMScript.Global.Bool](CRMScript.Global.Bool)\[] - True if the corresponding participant was successfully added, false if it could not be added because of filter criteria or other reason

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer emailFlowId;
Integer[] personIds;
Bool[] res = agent.TryAddPersonsToEmailFlow(emailFlowId, personIds);
```

## RemoveParticipantsFromEmailFlow(Integer,Integer\[])

Remove participants (actually workflow instances) from the workflow

```crmscript theme={null}
void RemoveParticipantsFromEmailFlow(Integer emailFlowId, Integer[] workflowInstanceIds)
```

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer emailFlowId;
Integer[] workflowInstanceIds;
agent.RemoveParticipantsFromEmailFlow(emailFlowId, workflowInstanceIds);
```

## CreateEmailFlowContent(Integer,String)

Create content to an email flow

```crmscript theme={null}
Integer CreateEmailFlowContent(Integer emailFlowId, String contentName)
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - Id of shipment created

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer emailFlowId;
String contentName;
Integer res = agent.CreateEmailFlowContent(emailFlowId, contentName);
```

## ConnectEmailFlowContent(Integer,Integer)

Link any SMessage to the email flow. The SMessage (and any related SShipment etc) should probably not be used/visible elsewhere.

```crmscript theme={null}
void ConnectEmailFlowContent(Integer emailFlowId, Integer messageId)
```

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer emailFlowId;
Integer messageId;
agent.ConnectEmailFlowContent(emailFlowId, messageId);
```

## CopyEmailFlowContent(Integer,Integer)

Copy smessage and connected shipment to the email flow. The SMessage (and any related SShipment etc) should probably not be used/visible elsewhere.

```crmscript theme={null}
Integer CopyEmailFlowContent(Integer emailFlowId, Integer shipmentId)
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - Newly created shipment id for this content

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer emailFlowId;
Integer shipmentId;
Integer res = agent.CopyEmailFlowContent(emailFlowId, shipmentId);
```

## UpdateFormSubmissions(Integer)

Attempt to update stored field values for up to the given number of form submissions

```crmscript theme={null}
Integer UpdateFormSubmissions(Integer maxCount)
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - Number of form submissions converted

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer maxCount;
Integer res = agent.UpdateFormSubmissions(maxCount);
```

## SetStatusOnWorkflow(Integer,WorkflowDefinitionStatus)

Set status on workflow, Run or pause flow

```crmscript theme={null}
WorkflowDefinitionStatus SetStatusOnWorkflow(Integer emailFlowId, WorkflowDefinitionStatus status)
```

**Returns:** [CRMScript.NetServer.WorkflowDefinitionStatus](CRMScript.NetServer.WorkflowDefinitionStatus) - The new status

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer emailFlowId;
WorkflowDefinitionStatus status;
WorkflowDefinitionStatus res = agent.SetStatusOnWorkflow(emailFlowId, status);
```

## CopyEmailFlow(Integer,String)

Copy an email flow.

```crmscript theme={null}
Integer CopyEmailFlow(Integer emailFlowId, String newName)
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - Newly created email flow id for this content

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer emailFlowId;
String newName;
Integer res = agent.CopyEmailFlow(emailFlowId, newName);
```

## Run()

Run the workflow engine right now

```crmscript theme={null}
DateTime Run()
```

**Returns:** [CRMScript.Global.DateTime](CRMScript.Global.DateTime) - Suggested time for next run

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
DateTime nextRun = agent.Run();
```

## SendEvent(NSWorkflowEvent)

Send a workflow event. Most event signaling will finish very quickly as they normally just change the state of a workflow instance

```crmscript theme={null}
NSWorkflowEventResult SendEvent(NSWorkflowEvent workflowEvent)
```

**Returns:** [CRMScript.NetServer.NSWorkflowEventResult](CRMScript.NetServer.NSWorkflowEventResult) - Any relevant info about the event

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
NSWorkflowEvent event;
NSWorkflowEventResult res = agent.SendEvent(event);
```

## GetWorkflowGoal(Integer)

Gets a NSWorkflowGoal object.

```crmscript theme={null}
NSWorkflowGoal GetWorkflowGoal(Integer workflowGoalId)
```

**Returns:** [CRMScript.NetServer.NSWorkflowGoal](CRMScript.NetServer.NSWorkflowGoal) - NSWorkflowGoal

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer workflowGoalId;
NSWorkflowGoal goal = agent.GetWorkflowGoal(workflowGoalId);
```

## GetWorkflowStep(Integer)

Get Workflowstep by ID

```crmscript theme={null}
NSWorkflowStepBase GetWorkflowStep(Integer workflowStepId)
```

**Returns:** [CRMScript.NetServer.NSWorkflowStepBase](CRMScript.NetServer.NSWorkflowStepBase) - The Workflow step

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer workflowStepId;
NSWorkflowStepBase step = agent.GetWorkflowStep(workflowStepId);
```

## AddAfterWorkflowStep(Integer,NSWorkflowStepBase)

Add another step (and any of its substeps) after the given step id (which must exist), and move any following steps in the workflow further down the line.

```crmscript theme={null}
NSWorkflowStepBase AddAfterWorkflowStep(Integer workflowStepId, NSWorkflowStepBase subStep)
```

**Returns:** [CRMScript.NetServer.NSWorkflowStepBase](CRMScript.NetServer.NSWorkflowStepBase) - The added step

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer workflowStepId;
NSWorkflowStepBase subStep;
NSWorkflowStepBase res = agent.AddAfterWorkflowStep(workflowStepId, subStep);
```

## CreateDefaultWorkflowStepFromType(WorkflowStepType)

Creates a new carrier from the step type given, with the right kind of properties, defaults set.

```crmscript theme={null}
NSWorkflowStepBase CreateDefaultWorkflowStepFromType(WorkflowStepType stepType)
```

**Returns:** [CRMScript.NetServer.NSWorkflowStepBase](CRMScript.NetServer.NSWorkflowStepBase) - The created workflow step

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
WorkflowStepType stepType;
NSWorkflowStepBase res = agent.CreateDefaultWorkflowStepFromType(stepType);
```

## GetWorkflowTrigger(Integer)

Gets a NSWorkflowTrigger object.

```crmscript theme={null}
NSWorkflowTrigger GetWorkflowTrigger(Integer workflowTriggerId)
```

**Returns:** [CRMScript.NetServer.NSWorkflowTrigger](CRMScript.NetServer.NSWorkflowTrigger) - NSWorkflowTrigger

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer workflowTriggerId;
NSWorkflowTrigger trigger = agent.GetWorkflowTrigger(workflowTriggerId);
```

## GetWorkflowWaitForAction(Integer)

Gets a NSWorkflowWaitForAction object.

```crmscript theme={null}
NSWorkflowWaitForAction GetWorkflowWaitForAction(Integer workflowWaitForActionId)
```

**Returns:** [CRMScript.NetServer.NSWorkflowWaitForAction](CRMScript.NetServer.NSWorkflowWaitForAction) - NSWorkflowWaitForAction

**Example:**

```crmscript theme={null}
NSWorkflowAgent agent;
Integer workflowWaitForActionId;
NSWorkflowWaitForAction action = agent.GetWorkflowWaitForAction(workflowWaitForActionId);
```

## CreateDefaultWorkflowStepOptionFromType(WorkflowSplitOptionType)

Creates a new carrier from the option type given, with the right kind of properties, defaults set.

```crmscript theme={null}
NSWorkflowStepOptionBase CreateDefaultWorkflowStepOptionFromType(WorkflowSplitOptionType optionType)
```

**Returns:** [CRMScript.NetServer.NSWorkflowStepOptionBase](CRMScript.NetServer.NSWorkflowStepOptionBase) - The created workflow step option.

## GetWorkflowStepOption(Integer)

Get WorkflowStepOption by ID.

```crmscript theme={null}
NSWorkflowStepOptionBase GetWorkflowStepOption(Integer workflowStepOptionId)
```

**Returns:** [CRMScript.NetServer.NSWorkflowStepOptionBase](CRMScript.NetServer.NSWorkflowStepOptionBase) - The Workflow step option.


## Related topics

- [SuperOffice.WebApi.Agents.WorkflowAgent](/en/api/reference/webapi/SuperOffice.WebApi.Agents.WorkflowAgent.md)
- [SuperOffice.WebApi.Agents.IWorkflowAgent](/en/api/reference/webapi/SuperOffice.WebApi.Agents.IWorkflowAgent.md)
- [Delete Workflow Goal](/en/api/reference/restful/agent/workflow_agent/delete-workflow-goal.md)
- [Delete Workflow Trigger](/en/api/reference/restful/agent/workflow_agent/delete-workflow-trigger.md)
- [Get Workflow Step](/en/api/reference/restful/agent/workflow_agent/get-workflow-step.md)
- [Save Workflow Goal](/en/api/reference/restful/agent/workflow_agent/save-workflow-goal.md)
