Examples of Workflows
Notify Parcel Shipped
Example of a workflow that adds a tracking event for parcel shipped.
workflow:
name: "Notify Parcel Shipped"
description: "Add tracking event for parcel shipped"
version: "1.0"
triggers:
- name: OrderStatusChanged
type: "Entity"
entityName: "Order"
eventType: "Modified"
position: "After"
activities:
- name: AddTrackingEvent
conditions:
- expression: "OrderContext.Order.OrderStatus.OrderStatusName == 'Shipped'"
description: "Add tracking event for parcel shipped"
steps:
- task: "script"
conditions: "OrderContext.Order.OrderStatus.OrderStatusName == 'Shipped'"
inputs:
type: "CSharp"
run: "
await OrderContext.AddTrackingEvent(OrderContext.Order.OrderId, 'Parcel Shipped');
"
Create Invoice for Processed Shipment"
Example of a workflow that creates an invoice for processed shipment orders that are awaiting payment.
workflow:
name: "Create Invoice for Processed Shipment"
description: "Create an invoice for processed shipment orders that are awaiting payment."
version: "1.0"
executionMode: "Async"
triggers:
- name: OrderStatusChanged
type: "Entity"
entityName: "Order"
eventType: "Modified"
position: "After"
conditions:
- expression: "(OrderContext.Order.OrderType == OrderTypes.ParcelShipment && OrderContext.Order.OrderStatus.OrderStatusName == 'Awaiting Payment')"
activities:
- name: GenerateInvoice
conditions:
- expression: "(OrderContext.Order.OrderType == OrderTypes.ParcelShipment && OrderContext.Order.OrderStatus.OrderStatusName == 'Awaiting Payment')"
description: "Generate invoice for child orders of processed shipment"
steps:
- task: "script"
conditions: "(OrderContext.Order.OrderType == OrderTypes.ParcelShipment && OrderContext.Order.OrderStatus.OrderStatusName == 'Awaiting Payment')"
inputs:
type: "CSharp"
run: "
var childOrders = await OrderContext.FindAllChildOrders();
await OrderContext.CreateInvoice(childOrders);
"
Set Parcel Status to Ready to Ship after Payment
Example of a workflow that sets the parcel status to 'Ready To Ship' after payment is processed.
workflow:
name: "Update Parcel Status After Payment Completion"
description: "Once an invoice is marked as paid, the associated parcel status is updated to 'Ready To Ship', and a 'Invoice Paid' tracking event is appended."
version: "1.0"
executionMode: "Async"
triggers:
- name: InvoicePaymentProcessed
type: "Entity"
entityName: "AccountingTransaction"
eventType: "Modified"
position: "After"
conditions:
- expression: "InvoiceContext.Invoice.AccountingTransactionStatus == AccountingTransactionStatus.Paid"
activities:
- name: ModifyParcelStatusPostPayment
conditions:
- expression: "InvoiceContext.Invoice.AccountingTransactionStatus == AccountingTransactionStatus.Paid"
description: "Update parcel status to 'Ready To Ship' once its related invoice is paid."
steps:
- task: "script"
conditions: "InvoiceContext.Invoice.AccountingTransactionStatus == AccountingTransactionStatus.Paid"
inputs:
type: "CSharp"
run: |
foreach (var order in InvoiceContext.Orders) {
if (await order.HasOrderStatus('Awaiting Payment')) {
await order.SetOrderStatus('Ready To Ship');
await order.AddTrackingEvent('Invoice Paid');
}
}
Update Order Tracking Events From Shipment Tracking App
Example of a workflow that updates the order tracking events from shipment tracking.
workflow:
name: "Refresh Order Tracking Events Using Shipment Data"
description: "Regularly update order tracking events based on shipment tracking details."
version: "1.0"
schedules:
- cron: "0 0 * * *"
displayName: "Every Day"
activities:
- name: updateOrderTrackingEvents
description: "Retrieve and update order tracking events using shipment tracking information."
steps:
- task: "script"
inputs:
type: "CSharp"
run: |
var orders = OrderContext.FindOrders("NOT Status.StatusName:'Delivered'");
foreach (var order in orders) {
Apps("TrackingApp").Invoke("GetTracking", order);
}