Extend Universal Resource Scheduling with Universal FetchXML
Article
UFX is an advanced query language that allows you to query data using dynamic FetchXML, shape, and prepare the resulting data for consumption by the Universal Resource Scheduling (URS) solution.
This query language enables you to create custom queries to customize and extend the schedule board and schedule assistant filters to meet the unique business needs of the organization.
UFX consists of two components UFX Bag and UFX Query.
Simple UFX Bag
A UFX Bag contains static typed data. In memory, it's represented as a dictionary with keys and values. It can be serialized to JSON and XML. Having the data typed allows a UFX Query to query data from it, and client UI to bind to it.
For practical and performance reasons the in-memory bag is implemented on top of the Dynamics 365 apps SDK Entity object.
UFX Queries are written as XML-based UFX Bags. Properties in the bag can contain UFX directives to query data dynamically. A UFX Query executes on in-memory objects, not XML. Only the directives are written in XML. Its output can be serialized to JSON or XML.
The following UFX Query defines the accounts property in the bag with the source UFX directive. This results in the inline FetchXML to be executed by Dynamics 365 and the accounts property to become a list of bags, or an EntityCollection, with each bag being an instance of an account record from Dynamics 365.
Certainly the most powerful aspect of a UFX Query is its ability to dynamically generate FetchXML based on input data.
In the sample below, we search for accounts by a value supplied by the user and available as a UFX Bag through the XPath $input variable. Notice the UFX if and value directives on the condition element.
A UFX Bag contains keys and values, with some values having additional metadata further describing them.
An example might be a value of type lookup (EntityReference). When queried from Dynamics 365 through FetchXML, it will return the logical name of the entity as well as the formatted display name of the record. The UFX Bag preserves these additional information as metadata attached to the primary value.
Serialized to JSON, a lookup with metadata looks like this:
Having the data in a UFX Bag typed, allows a UFX Query to see it in a structured format and use XPath to traverse over the data and select values from it.
An XPath expression specified in a UFX directive sees the data in the bag similar to the structure of the bag in XML-serialized form. However, the data is stored in in-memory .NET objects (in instances of Entity and EntityCollection types) and not in XML documents.
Appendix A: UFX type reference
Note: All UFX Types support the ufx-type and ufx-formatvalue metadata. Additional metadata are described next to each type in the table below.
UFX Name
Attribute Type Code
.NET Name
UFX Metadata
bool
Boolean
Boolean
int
Integer
Int32
long
BigInt
Int64
double
Double
Double
decimal
Decimal
Decimal
datetime
DateTime
DateTime
guid
Uniqueidentifier
Guid
string
Memo
String
money
Money
Money
option
Picklist
OptionSetValue
lookup
Lookup
EntityReference
ufx-logicalname
bag
N/A
Entity
ufx-id ufx-logicalname
list
N/A
EntityCollection
N/A
N/A
AliasedValue
ufx-aliasentity ufx-aliasattribute
Appendix B: UFX Query directives
UFX directives can be used on bag properties and on XML elements of a FetchXML query.
UFX Bag directives
Attribute
Value
Description
ufx:if
XPath
Tests the XPath expression and only processes the property if the test returns true
ufx:source
fetch
Executes the inline <fetch> XML element and assigns the result to the property
ufx:select
XPath
Executes the XPath expression and assigns the result to the property When querying for a bag or list an optional child bag in XML form can be specified to transform the result of the XPath expression
UFX FetchXML directives
Element
Attribute
Value
Description
All elements
ufx:if
XPath
Tests the XPath expression and only emits the XML element if the tests succeed
ufx:apply
select
XPath
Loops over the nodeset returned by the XPath expression and outputs the child XML elements once for each node
ufx:value
select
XPath
Executes the XPath expression and outputs the result in the current XML element
ufx:value
attribute
attribute name
Assigns the XPath expression result to the specified attribute name on the current XML element
Appendix C: UFX XPath functions
UFX adds a number of new functions in addition to the ones available natively in XPath.
datetime()
datetime(): Returns the current time in UTC
list()
list(bag | list, ...[bag | list]): Takes a number of bag or list values as input and flattens them into a single list
lookup-to-list()
lookup-to-list(lookup, ...[lookup]): Takes a number of lookup values, converts each of them to a bag with the ufx-id and ufx-logicalname metadata set, and flattens them into a single list
option-to-list()
option-to-list(option, ...[option]): Takes a number of option values, converts each of them to a bag with a single option property, and flattens them into a single list
order()
order(list, string, bool): Orders a list by a property in each bag. The property is specified in argument 2, descending is specified in argument 3.
order(list, list): Order a list by multiple sort orders specified as a list in argument 2. Each bag in the second list can have a name and descending property
iif()
iif(any, any, any): If argument 1 is true, returns argument 2, otherwise returns argument 3
Appendix D: UFX XPath variables
Name
Description
$input
A bag available to the UFX Query with input values
$null
A null constant. Selecting $null on a property removes the property from the bag
$current
Reference to the current bag being processed by the UFX Query
Schedule anything to the right resource for any job or task with ease. Universal Resource Scheduling (URS) is a Dynamics 365 solution that allows organizations from different industries with different scenarios.