Asynchronous vs Synchronous SharePoint Actions
Introduction
The Actions component of Ultimate Forms eases the pains of SharePoint automation. Designed with non-developers in mind, it's easier and faster to work with compared to traditional workflows.
Ultimate Forms works equally well in both SharePoint Online (Microsoft 365) and on premises. Both versions even have the identical user interface. This makes it easier to transfer your knowledge and experience.
With a wide selection of configurable action types, Actions can accomplish most common requirements both inside and outside SharePoint. And with our simple approach, you don't have to understand workflows and flowcharts. You configure and deploy each action individually without any dependencies.
You implement automation using actions by performing the following steps:
- Select the SharePoint site and SharePoint list or document library
- Select the action type
- Select trigger[s]
- Configure action-specific settings. For example, with Update list item action, you specify which item to update and what columns to update.
- Optionally add conditions. You might only want to run the action when certain conditions apply.
One helpful setting here is "after change" conditions. The "after change" setting allows you to only run the action when a particular change takes place. For example, Status after change equals Completed will only run when the current update changed the Status column value to Completed.
Action Triggers
Actions triggers is what causes actions to start executing. Ultimate Forms offers a comprehensive selection of trigger types. This makes triggering actions simple, adjustable and suitable for every need.
Ultimate Forms offers 4 different types of action triggers:
- List events: a user adds, modifies, deletes, checks in/out or moves SharePoint list items. You can also detects when a user adds or deletes list item attachments.
- Timer: based on any date column within the item (e.g. "2 days before Due Date") or daily/weekly/monthly at a predefined hour.
- Manual: by clicking on the execution button in toolbars or directly inside a list form. The Run Actions button on toolbars will list all actions marked as Manual. Users can trigger the actions directly from there and track their progress. You can also place a button on your modern SharePoint form of the type Trigger action.
- Form events: a form can trigger actions on different events, for example when the form opens. This is especially useful in some logging scenarios.
- Action group: a special action type Action Group triggers the actions it contains. You can use action groups to trigger multiple actions with the same button click. Another unique capability of action groups is repeated execution according to range of values. For example, executing for each date between two dates.
You can mix and match all available trigger types. The same action can run under different triggers if needed.
Current Item
Actions have a concept of "current item". This is the item which originally triggered the action. For example, if the action runs on Item is added, this is the item you just added. When you add conditions to the actions, the properties of the current actions are the ones you refer to in your conditions.
In some action types, for example, Update list item, the current item must not be the target of the update. You can choose any item or items in any list in any site. It can even apply to items in a completely different site collection. However, you still use the values from the current item on the right-hand side when settings values for columns or using conditions.
Timer trigger allow you to run your action action that execute on a particular interval. For example, it can run every day at a particular hour. As such, there is no current item by default.
You can provide at least one "static" condition for the action to select its current items. A static condition is one that does not reference any column values on the right. It allows the system to apply the condition without a current item. For example, Status = Completed is a static condition, because the value on the right (Completed) is just text.
The action will execute the static conditions first. That will produce the list of one or more items. The action will then execute on each, receiving it as its current item.
If you provide no static conditions, the action will just use the first item from the list as the Current Item.
Asynchronous and Synchronous Actions
If you switch to the Advanced Settings tab of the action, you will notice that you can set an action to run synchronously. This setting only matters for list event-based actions, it does not change anything for other trigger types. The default setting is for the action to run asynchronously.
To understand what this setting means, let's explore how SharePoint updates work. When you add/edit your list item and click on Save, there are two events being triggered:
- Before the actual database update
- After the actual database update.
The Before event happens before SharePoint writes the changes back to the database. Because of this fact, you still have the ability to cancel the update at this stage. The After event happens after the update, so there is no way of reverting the change at this point.
Asynchronous Actions
Asynchronous actions continue their execution in the background even after the form closes. No visual indication exists for the user that the action is still running.
Asynchronous actions are great for any long running operations. For example, updating multiple items, creating sites or calling web services. Generally, unless specifically required, all your actions should be asynchronous.
Bear in mind though, that asynchronous action might still need to update the current item when done. One common need is to update the current item for logging purposes. Or it might be of the type Update list item and set to modify the current item.
Therefore the action will perform a secondary update on the list item. This second update might trigger additional actions on the list. Our system will ensure secondary updates don't trigger more actions on the same items, to prevent an infinite loop.
Synchronous Actions
Synchronous actions in SharePoint run differently. They will actually execute before the database update. Without using Actions, the only way to implement synchronous execution in SharePoint is by the means of custom code.
Don't plan any long-running action to execute synchronously, it's not a good idea. If the action takes a long time, the form would appear to remain stuck.
Two main reasons to use synchronous actions are:
- No secondary update - you might have a requirement not to update the item the second time. For example, you might not want there to be another entry in the version history. Synchronous actions inject their changes to the update already in progress. This way it all appears as a single update and create a single entry in the version history.
- Cancel update - in some cases you might want to cancel the update in progress and display an error to the user. For example, in resource booking scenarios, you need to prevent double-booking. You use an action to check if there are existing reservations for the same resource. If the action finds existing bookings for the same resource and time period, it raises an error on the form.
To learn more about double-booking scenarios install our Room Reservation solution that implements this approach.
Final Thoughts
So as you see, there are multiple different options for action triggering. That give you precise control over how and when to run your actions. Combined with the overall simplicity, Actions are great tool for any novice and experienced SharePoint developer.