Uncategorized

Callbacks

Introduction

Callbacks in Formatted Reports enable automated data transfer and task initiation by passing a table of data to a datafeed or kicking off a scheduled task. This feature integrates user-entered data from formatted reports directly into Quintessence, streamlining workflows and enabling automatic data uploads or task scheduling.

Example of a Callback to a Datafeed

The following IronPython script creates a formatted report with a callback to a datafeed, illustrating four methods for assigning data to the callback.

# IronPython

data = Qx.ToMatrix([
  ["Upload Example", "", "Date", Qx.Date("2024-01-01"), "", "Interim"],
  ["", "", "", "", "", ""],
  ["Code", "Name", "Percentage", "Value", "Select", "Comment"],
  ["DELL", "DELL STOCK",  0.45, 1000.00, "Red", ""],
  ["MSFT", "MICROSOFT STOCK",  0.30, 2500.00, "Green", ""],
  ["APPL", "APPLE CORPORATION",  0.25, 2000.00, "Blue", ""],
  ["", "", "", "", "", ""]
])

sheet = Qx.MakeStyleSheet(data)

sheet.Cell(0,5).Name = "AttributeValue"

# Create a callback for the 3 comment cells in the report
# Each cell in the callback selection will result in one row sent to the datafeed
# The columns sent to the datafeed can be populated using the SetThis and SetRelative methods
callback = sheet.Box(3,5,3,1).Callback("DataFeed","Upload Analyst Comment")  # Specify DataFeed as the callback type and provide the name for the feed
callback.Data.SetThis("Analyst Comment")  # Use the SetThis method to specify under which column name the data in this selection should be passed to the feed
callback.Data.SetRelative("Instrument Code", 0, -5)  # Use the SetRelative method to specify additional data columns to be sent to the feed
callback.Data.SetAbsolute("Value Date", 0, 3)  # All rows sent to the feed will refer to the date in row 1, column 4
callback.Data.SetNamed("Attribute","AttributeValue")  # Assign a value to the attribute column by referring to a cell in the stylesheet that was given a name

sheet

Explanation of Methods Used in Callback Configuration

  1. SetThis: Assigns a specific column name under which the data in the selected cells will be passed to the datafeed.
   callback.Data.SetThis("Analyst Comment")
  1. SetRelative: Specifies additional columns for the datafeed by referencing cells relative to the selected data’s location.
   callback.Data.SetRelative("Instrument Code", 0, -5)  # Relative to current cell position
  1. SetAbsolute: Uses an absolute reference to include a fixed cell value (e.g., a date) across all rows sent to the datafeed.
   callback.Data.SetAbsolute("Value Date", 0, 3)  # Fixed date at row 1, column 4
  1. SetNamed: Refers to a named cell in the stylesheet, linking it to a specific column in the datafeed.
   callback.Data.SetNamed("Attribute","AttributeValue")

This callback example configures data submission to a datafeed by setting a flexible data structure, allowing for quick updates and easy data uploads.

Example of a Callback for a Scheduled Task

In addition to sending data directly to a datafeed, callbacks can also initiate scheduled tasks, passing data to the datafeed to load into Quintessence. The following example demonstrates how to configure a scheduled callback.

# IronPython

data = Qx.ToMatrix([
  ["Upload Example", "", "Date", qx.Date("2024-01-01"), "", "Interim"],
  ["", "", "", "", "", ""],
  ["Code", "Name", "Percentage", "Value", "Select", "Comment"],
  ["DELL", "DELL STOCK",  0.45, 1000.00, "Red", ""],
  ["MSFT", "MICROSOFT STOCK",  0.30, 2500.00, "Green", ""],
  ["APPL", "APPLE CORPORATION",  0.25, 2000.00, "Blue", ""],
  ["", "", "", "", "", ""]
])

sheet = Qx.MakeStyleSheet(data)

sheet.Cell(0,5).Name = "AttributeValue"

# Link the callback to the 3 comment cells in the report
# Each cell in the callback selection will result in one row sent to the datafeed
# The columns sent to the datafeed can be populated using the SetThis and SetRelative methods
callback = sheet.Box(3,5,3,1).Callback("Schedule", "Upload Analyst Comments")
UploadDataTable = callback.Table("UploadData")
UploadDataTable.SetThis("Analyst Comment")  # Use the SetThis method to specify under which column name the data in this selection should be passed to the feed
UploadDataTable.SetRelative("Instrument Code", 0, -5)  # Use the SetRelative method to specify additional data columns to be sent to the feed
UploadDataTable.Set("Value Date", Qx.DateOffset(-1))  # Use the Set method to set a column to a static value
UploadDataTable.SetNamed("Attribute","AttributeValue")  # Assign a value to the attribute column by referring to a cell in the stylesheet that was given a name

In this example:

  • The callback is configured to trigger a Schedule task.
  • UploadDataTable.SetThis specifies the column for analyst comments.
  • UploadDataTable.SetRelative allows additional information, such as the instrument code, to be included.
  • UploadDataTable.Set assigns a static value to a column, here using a date offset.
  • UploadDataTable.SetNamed references a named cell in the stylesheet to pass an attribute value.

Additional Callback Settings

Several settings can be applied at the sheet level to manage callback behavior:

callback = sheet.Callback("Schedule", "Upload Analyst Comments")

callback.Collapse = True  # Multiple sheets referring to the same callback will result in a single call
callback.Name = "Test"  # Optional, but useful for better feedback and tracking
callback.Ordinal = 1  # Sets the order in which callbacks are run, with lower numbers running earlier
  • Collapse: Ensures that multiple sheets referencing the same callback trigger only one call, simplifying workflows.
  • Name: An optional name that can be set for better tracking and clearer feedback.
  • Ordinal: Specifies the order of execution for callbacks, with lower ordinal numbers running earlier.