If you define entity key by key clause You receive entity specified by the key. You can define key as parameter of the EntitySet.get method
service.C_AllocationCycleTP.get({
AllocationType: "ACDOC_CC",
AllocationCycle: "0LATAF2_3",
AllocationCycleStartDate: "datetime'2017-01-01T00%3A00%3A00'",
DraftUUID: "guid'00000000-0000-0000-0000-000000000000'",
IsActiveEntity: "true",
});
or you can defined key by EntitysSet.key method
service.C_AllocationCycleTP.key({
AllocationType: "ACDOC_CC",
AllocationCycle: "0LATAF2_3",
AllocationCycleStartDate: new Date("2017-01-01T00:00:00"),
DraftUUID: "00000000-0000-0000-0000-000000000000",
IsActiveEntity: "true",
}).get();
Use select
clause to limits properties returned from the OData server.
var service = new Service();
service.init
.then(() => {
return service.AllocationCycle.select(
"AllocationCycle",
"AllocationCycleStartDate"
).get();
})
.then((res) => {
console.log(
"Only AllocationCycle and AllocationCycleStartDate are in results ... ",
body.d.results
);
});
The select
method accepts array also.
service.AllocationCycle.select([
"AllocationCycle",
"AllocationCycleStartDate",
]).get();
If you try pass top clause to not countable EntitySet You raise exception .
Use the $filter clause to filter out non matching entities. The filter definition is automatically encoded to URL.
var service = new Service();
service.init.then(() => {
return client.AllocationCycle.filter("AllocationType eq 'ACDOC_CC'")
.get()
.then((cycles) => {
/* your processing */
});
});
Use top clause to limit number of responded entities
var service = new Service();
service.init
.then(() => {
return service.AllocationCycle.top(1).get();
})
.then((res) => {
console.log("Just one entity returned ... ", body.d.results.length);
});
You can set number as parameter of get method to use top also
service.AllocationCycle.get(1);
If you try pass top clause to not countable EntitySet You raise exception .
Use orderby clause to specify an expression for determining what values are used to order the collection of Entries. This query option is only supported when the resource path identifies a Collection of Entries.
service.C_AllocationSegmentTP.orderby(
"AllocationCycleStartDate",
"AllocationCycleSegment desc"
)
.get()
.then((data) => {
// ...
});
The '$expand' option allows you to identify related Entries with a single URI such that a graph of Entries could be retrieved with a single HTTP request.
Multiple navigation properties can be expanded at once. expand
method accepts array or multiple arguments.
Also nested navigation properties can be expanded. Navigation properties has to be separated by /
.
service.C_UI5NetworkGraphGroup
.expand(["to_Node/to_Attribute", "to_Node/to_Line"])
.get();
.then(data => {
// ...
});
OData define set of standard parameters which could be added to the url or you can implement other parameters in your server.
service.C_AllocationCycleTP.queryParameter("$format", "json")
.queryParameter("$top", "10")
.get();
Hint
You could pass some standard parameters like $top which is also implemented as
special clause by queryParameter
, but particular methods like service.C_AllocationCycleTP.top
contains additional checks implemented on the library side.
Use count method to get number of entities in EntitySet.
var service = new Service();
service.init
.then(() => {
return service.AllocationCycle.count();
})
.then((res) => {
console.log(`EntitySet contains ${res} entities.`);
});
You can set number as parameter of get method to use top also
service.AllocationCycle.get(1);
Parametrized CDS views creates parametrized entity sets. These can be read as follows:
service.C_DAYSPAYABLESOUTSTANDING.parameters({
P_PyblsRollingAverageMonths: 2,
P_PurRollingAverageMonths: 2,
P_DisplayCurrency: "EUR",
P_ExchangeRateType: "M",
}).get(10);
Parametrized entity types are different in analytical and in transactional services, this api works for both.
You can read association referenced by a NavigationProperty from any EntitySet that has already initialized key
service.C_AllocationCycleTP.key({
AllocationType: "ACDOC_CC",
AllocationCycle: "0LATAF2_3",
AllocationCycleStartDate: "datetime'2017-01-01T00%3A00%3A00'",
DraftUUID: "guid'00000000-0000-0000-0000-000000000000'",
IsActiveEntity: "true",
}).to_Segment.get();
Based on the multiplicity defined in metadata document the result of the promise is either single entity or array
The Association acts almost the same like EntitySet so you can for example specify query parameters or a key for the resource
service.C_AllocationCycleTP.key({
AllocationType: "ACDOC_CC",
AllocationCycle: "0L14011902",
AllocationCycleStartDate: "/Date(1547424000000)/",
DraftUUID: "42f2e9af-c507-1ed9-8bbb-f206cf2596a5",
IsActiveEntity: false,
})
.to_Segment.get({
AllocationType: "ACDOC_CC",
AllocationCycle: "0L14011902",
AllocationCycleStartDate: "/Date(1547424000000)/",
AllocationCycleSegment: "0001",
DraftUUID: "42f2e9af-c507-1ed9-8bbb-f2fb9b4476a7",
IsActiveEntity: false,
})
.then((segment) => {
//...
});
Unfortunately the Netweaver implementation of the oData protocol does not support nested navigation in one request so this is not possible:
service.C_ParentEntity.key({
//...
})
.to_Children.key({
//...
})
.to_GrandChildren.get()
.then(() => {
// throws error
});
The Netweaver backens support requests to binary data (typically PDF or Excel documents). OData library correctly process three MIME types.
application/pdf
application/vnd.ms-excel
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
The request definition for binary data is same like request to navigation property.
The navigation property which provide binary data has to be marked as HasStream
in metadata. Response is Buffer
which contains received binary data.
Common use of navigation property with relation 1:1 is producing stream.
service.Items.key({
ApplObjectType: "PARAGON",
ApplObjectId: "31415926",
ItemId: "1"
}).GetDocument.value().get();
})
.then((dataBuffer) => {
parsePdf(dataBuffer);
});
Read stream entity with entity definiton. The example
service.C_AllocationCycleTP.filter("IsActiveEntity eq true")
.top(1)
.get()
.then((result) => {
return service.AllocExcelTemplateSet.key({
cycle: [
result[0].AllocationType,
result[0].AllocationCycle,
new Date(
parseInt(
result[0].AllocationCycleStartDate.match(/\/Date\((\d+)\)\//)[1],
10
)
)
.toISOString()
.replace(/(-|T.*)/g, ""),
].join(","),
})
.value()
.get();
})
.then((result) => {
assert.ok(result instanceof Buffer);
});
Use raw
method to use plain response from Fetch API instead
of parsed data from OData response.
service.C_AllocationCycleTP.raw()
.get({
AllocationType: "ACDOC_CC",
AllocationCycle: "0LATAF2_3",
AllocationCycleStartDate: "datetime'2017-01-01T00%3A00%3A00'",
DraftUUID: "guid'00000000-0000-0000-0000-000000000000'",
IsActiveEntity: "true",
})
.then((res) => {
console.log(res);
});