ExecuteODataQuery<>

alert Prerequisite: When this activity is used with Anthology Student 21.2.0 and later, the APIUser must have authorization to access to the entity requested in the OData query. For more information, see Security Enhancement for OData Queries.

The ExecuteODataQuery<> activity returns an OData query against the query model. The result of the OData query can be used as input for subsequent workflow activities.

The results of the OData query are available in the body of the activity. The results are iterated, and each item returned is available using the item variable. The ExecuteODataQuery<> is useful when you want to retrieve a list of students, courses, or any entity, and you want to perform the same activity using each entity returned in the list.

For example, you could use this activity to:

  • Get a class roster for student’s in a class section and send an email to each student.

  • Get a list of all student’s in a student group or hold group and charge each one a late fee.

Note: This activity does not return entities. A conversion assignment needs to be made to bind query result to the entity model. Once bound, the data can be edited. For an example of how to bind OData query results to a grid in a form sequence, see the Forms Builder help topic Grid Bound to Results of ExecuteODataQuery Activity.

When ExecuteODataQuery<> activity is dropped into the Designer pane, the workflow dialog prompts for the <TQuery>, which is the model type to query against. The Browse for Type... option must be used to select the query model type. Closed

Browse for Types

All query model types are located in the Cmc.Nexus.Models namespace. Closed

Namespace Cmc.Nexus.Models

The model type selected in the Cmc.Nexus.Models namespace must match the primary type for your OData query. For example, if the primary type in the OData query is <Students>, the TQuery model type must also be <Students>.

Note: The Cmc.Nexus.Models.{module}.{type} namespace for the selected model type must be available in Workflow Composer so that the results of the OData query can be assigned. Otherwise an error message will be displayed. To avoid errors such as “'<entity>' is not defined”, in the body of the ExecuteODataQuery<> activity, add any activity (e.g., WriteLine or LogLine) with specific value to be written or logged. e.g., item.FirstName (or whatever is applicable for the OData query). Adding an activity ensures that the Imports required for the selected namespace are set properly. If you do not include an activity in the body of the ExecuteODataQuery<> activity, add the required namespace to the Imports tab in Workflow Composer.

To create an OData query, you can use the Web Client for Anthology Student. It is easiest to get the OData query results in a browser first to verify that the query is valid and that it returns the expected results. Once you have the desired query and results, paste the query into the QueryText field in the Properties pane of the ExecuteODataQuery<> activity. Enclose the query string in double quotes.

Example

"http://<localhost>/Cmc.Nexus.Web/ds/campusnexus/Student/Shifts?$orderby=Name"

QueryText

Optionally, the query results can also be stored in variables.

  • The raw JSON string result is available via the RawODataResults property.

  • If the total count of items returned by the query is needed, the ItemCount property can be used.

  • The collection of items can be saved to a variable by providing the properly typed variable in the ResultsCollection property.

    For the ExecuteODataQuery<Shift> example, the variable type needs to be IEnumerable<Shift>. The variable must have a default value of new List(of cmc.Nexus.Models.Academics.Shift). Closed

    Variables

    To view the query result with the above property settings in the Output pane, insert a WriteLine activity that displays "Count " & shiftCount.

Navigational properties are also available in the results. For example, if the main query is on the Students type, the Person navigation property will be available to get the Person. FullName. A requirement for using the properties is that the OData query must include an $expand parameter to expand the navigation property.

Example

Query to select the top 10 students and expand the Person property, selecting just the FullName:

http://<studentwebclientbaseurl>/ds/campusnexus/Students?$select=Id&$expand=Person($select=FullName)&$top=10

Within the workflow, the FullName can be accessed as item.Person.FullName.

Properties

ExecuteODataQuery Properties
Property Value Required Notes
DisplayName String No Specify a name for the activity or accept the default.
ItemCount OutArgument<Int32> No This property can be used to capture the total count of items returned by the query.
QueryText InArgument<String> Yes Specify the OData query string. Make sure the string is enclosed in double quotes.
RawODataResults OutArgument<String> No This property can be used to provide the raw JSON string result.
Result OutArgument<TQuery> No This property is not supported. Please use the ResultsCollection property.
ResultsCollection InOutArgument<IEnumerable<TQuery>> No Use this property to save the collection of items to a variable. The variable type must be IEnumerable<TQuery>) and a default value must be defined.

ExecuteODataQuery<> Example

  1. Drag the ExecuteODataQuery<> activity from the “Cmc.Core.Workflow.Activities” namespace into the Designer pane.

  2. Select Browse for Types … in the TQuery drop-down list.

  3. Navigate to the Cmc.Nexus.Models namespace. For this example, we will use the Shift model in the Academics namespace. Selecting “Shift” means that the OData query will be written using “Shifts” as the primary model.

    Type=Shift

  4. Click OK to close the Select Types dialog.

  5. Paste the OData query into the QueryText field of the Properties pane. Make sure to add the string value surrounded by double quotes. In our example, the OData query is:

    "http://<studentwebclientbaseurl>/ds/campusnexus/Shifts?$orderby=Name"

  6. To capture the query results in the Output pane of Workflow Composer, drop a WriteLine activity into the body of the ExecuteODataQuery<> activity. Specify item.Name in the Text field of the WriteLine activity.

    Write Line

  7. Click . The Name of each shift is written to the Output pane.

    Output