Order Update Script

Modified on Fri, 20 Mar at 12:09 PM

Overview

The Order Update Script allows you to automate updates to orders based on specific triggers and logic. This includes:

  • Finding and adding Hubs for multi-segment orders

  • Responding to Order Events

  • Importing and using external spreadsheet data

  • Updating delivery pricing dynamically


Finding a Hub

Hubs are configured as Addresses of type Hub and can be retrieved within scripts.

To search for hubs, use:

var hubs = await data.FindHubs("HUB Name");
  • The input string can be a Company Name or Hub Name

  • The result may return multiple hubs

From the results, you can retrieve:

  • Hub ID

  • Hub Address

  • Hub Contact Information

Note: Only addresses defined as Hub type can be retrieved using this method.

For more details, refer to the model:
IScriptDataProvider.cs
https://github.com/dispatchscience/DispatchScience.Scripting/blob/main/Dispatch.Scripts.Abstractions/Models/IScriptDataProvider.cs


Adding a Hub to an Order

Once you have retrieved a Hub ID, you can add it to an order to create a Multi-Segment Order.

Example:

await order.AddHubs(hubId);

Workflow:

  1. Use FindHubs() to locate the desired hub(s)

  2. Extract the Hub ID

  3. Add the hub to the order using AddHubs()

For more details, refer to:
HubInfo.cs
https://github.com/dispatchscience/DispatchScience.Scripting/blob/main/Dispatch.Scripts.Abstractions/Models/HubInfo.cs


Order Events

Order Update Scripts can be triggered based on specific Order Events.

To retrieve available events:

var events = await data.GetEventNames();

This allows you to:

  • Identify which events trigger updates

  • Apply logic only when specific changes occur


Script File (Excel Integration)

Order Update Scripts now support importing an Excel spreadsheet directly into the Script Rule.

This enhancement replaces the need for static script parameters and allows for more dynamic and scalable configurations.

The same GetSheet models used in Extra Fee Scripts are supported.


Import an Order Update Script Spreadsheet

  1. Navigate to Settings > System > Script Rule

  2. Open an existing Script Rule

  3. Locate the File section

  4. Click Choose File

  5. Select your Excel file and click Open

  6. Click Save



Once uploaded, the file name will appear in the Script Rule.

Accessing the File in Script

Use the GetSheet method to retrieve spreadsheet data within your script.


Download an Order Update Script Spreadsheet

  1. Go to Settings > System > Script Rule

  2. Open the desired Script Rule

  3. Click Download File




Delete an Order Update Script Spreadsheet

  1. Navigate to Settings > System > Script Rule

  2. Open the Script Rule

  3. Click the trash can icon

  4. Click OK to confirm deletion or Cancel to keep the file

  5. Click Save if required




Updating Delivery Price

The Order Update Script allows you to override or add a delivery charge on an order.

Method:

await order.OverrideDeliveryCharge(decimal basePrice);

Behavior:

  • Updates the delivery price if it already exists

  • Adds the delivery price if it is missing or invalid


Key Notes

  • Hub-related functionality is limited to Hub-type addresses only

  • Multiple hubs may be returned when searching—ensure you select the correct one

  • Excel integration allows for more flexible and maintainable scripting logic

  • Delivery charges can be dynamically controlled through scripts

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article