Select Transform
The select request transform allows authors to construct the query param, to include fields whose values need to be included, in the response. Example, the built-in Business Objects based transforms creates a 'fields' query parameter.
The select criteria provided via the options
parameter is an Object with properties { attributes, type }. The type is the response type structure typically specified on the ServiceDataProvider and Call Rest action configurations. The attributes are provided by the caller, such as the component, through a fetch call. See JET Data Provider docs for details on the fetch methods and the parameters. particularly 'attributes' (JET FetchAttribute). When attributes
and type
are present, how these are combined is left to the discretion of the transforms' implementation.
Examples
select criteria with type
transforms to "fields=PartyId,PartyStatus,PartyType;PrimaryAddress:AddressId,FormattedAddress"
{
"attributes": null,
"type": [
{
"PartyId": "number",
"PartyStatus": "string",
"PartyType": "string",
"PrimaryAddress": [
{
"AddressId": "number",
"FormattedAddress": "string"
}
]
}
]
}
select criteria with attributes
transforms to fields=a;b:b1,b2;c:c2;c.c1:c1a,c1b'
{
"attributes": [
"a",
{
"name": "b",
"attributes": [
"b1",
"b2"
]
},
{
"name": "c",
"attributes": [
{
"name": "c1",
"attributes": [
"c1a",
"c1b"
]
},
"c2"
]
}
],
"type": null
}
select criteria with both type and attributes transforms to fields=PartyId,PartyStatus,PartyType,a;PrimaryAddress:AddressId,FormattedAddress,b;PrimaryAddress.FormattedAddress:c
{
"attributes": [
"PartyId",
{
"name": "PrimaryAddress",
"attributes": [
"AddressId",
{
"name": "FormattedAddress",
"attributes": [
"c"
]
},
"b"
]
},
"a"
],
"type": {
"items": [
{
"PartyId": "number",
"PartyStatus": "string",
"PartyType": "string",
"PrimaryAddress": [
{
"AddressId": "number",
"FormattedAddress": "string"
}
]
}
]
}
}
For 3rd party services the author can provide a custom select transforms implementation.
Signature
The filter transform function can be declared like this:
function(configuration, options, transformsContext) {
var c = configuration;
// use the select criteria provided on 'options' parameter to generate the query param
// update c.url as needed
return c;
}
This function has the following parameters:
configuration
an object with the following properties:- Refer to the signature in Request Transformation Functions for details on the various properties.
options
select the fields whose data is requested:type
: an Object that is configured asresponseType
property on the Service Data Provider or Rest Actionattributes
: a structure defined by JET that is an Array<(string|FetchAttribute)>. See JET docs for details.
transformsContext
is an object that is set by the author (ServiceDataProvider, RestHelper, Call Rest action) to then be passed as is to all transforms for the current fetch cycle.
The function returns the updated configuration
object.
Usage
The examples below illustrate the arguments passed to the select transform, as well as the effect its code has on the fetch performed by the RestHelper.
The example below uses a service fixitfast
that has a GET endpoint to retrieve the list of customers.
Example 1-13 ServiceDataProvider variable
Assume that the following variable of type vb/ServiceDataProvider is defined in a page that refers to the above GET /customers endpoint. The SDP variable includes a response type that it expects the response to be in, set via the property responseType
.
{
"types": {
"customerResponse": {
"PartyId": "number",
"PartyStatus": "string",
"PartyType": "string",
"PrimaryAddress": [
{
"AddressId": "number",
"FormattedAddress": "string"
}
]
}
},
"variables": {
"customersSDP": {
"type": "vb/ServiceDataProvider",
"defaultValue": {
"endpoint": "fixitfast-service/getCustomers",
"keyAttributes": "PartyId",
"itemsPath": "result",
"responseType": {
"items": "customerResponse"
}
}
}
}
}
When a caller such as a component bound to the above SDP initiates a fetch call, it can also provide additional attributes. These are combined with the configured responseType
above and the combined select criteria is provided to the select transforms function.
The select
request transforms function uses the criteria passed in via the options
parameter to build a query param on the configuration url. The select
transform is implemented in the service transforms as follows:
define([], function () {
class Request {
static select(configuration, options, transformsContext) {
const c = configuration;
const selectOpts = options;
// process options to build the query param for the fields requested in the response
if (selectOpts && (selectOpts.type || selectOpts.attributes)) {
// ...
}
// update the c.url
return c;
}
}
var Response = function() {};
var Metadata = function() {};
// Note: as an example, the Request object is expanded to include just the select property
return {
metadata: Metadata,
request: { select: Request.select },
response: Response
};
});