Retrieve Entity Offline

0
Hi everyone, We have an offine app and are creating a widget. We have difficulty in retrieve objects from datasource. Let's say, in the model, we have Entity1 (1)------->(*) Entity2 My questions are: How we can get all objects of Entity1 Suppose we have an object as instance of Entity1, how we get objects of Entity2 connected to it. So far, we try: mx.data.get({ aggregates: false, count: true, xpath: "//ModuleName.Entity1", callback: function (results) {}, error: function () { } }); To get all object of Entity1, but it doens't work. mx.data.get({ aggregates: false, count: true, xpath:"//Module.Entity2[ModuleName.E2_E1=\"objE1Id\"]", callback: function (results) { }, error: function () { } }); or mx.data.get({ guid: objE1Id, aggregates: false, count: true, path:"ModuleName.E2_E1", callback: function (results) { }, error: function () { } }); But they don't work either. Does anyone know answers for our questions? Best regards
asked
2 answers
5

Here are some preliminary docs on the internal API used to fetch data when running offline (these can still change, so use at your own risk):

Description

Retrieve MxObjects when running offline.

  mx.data.getSlice(
    entity: string,
    constraints: Object[],
    filter: Object,
    callback: (objs: MxObject[], count: number) => void,
    error: (e: Error) => void
  )

Parameters

  • entity - the entity of the objects to retrieve
  • constraints[].attribute - the attribute to constrain on. This can also be a reference attribute.
  • constraints[].operator - the operator to constrain with. One of equals, lessThan, lessThanOrEquals, greatherThan, greaterThanOrEquals, contains.
  • constraints[].value - the value to constrain with
  • constraints[].negate - if true, return the objects not matching the constraint
  • filter.offset - filter.offset index from where to start in the results
  • filter.limit - maximum number of objects in the result
  • filter.sort - attribute and sort order pairs on which to sort the objects
  • callback - function to handle the result
  • error - function to handle errors

Examples:

 mx.data.getSlice("MyFirstModule.Pet", null, null, function(mxobjs, count) {
   console.log("There are " + count + " pets");
 });

 mx.data.getSlice("MyFirstModule.Pet", {
   attribute: "MyFirstModule.Pet_Person",
   operator: "equals",
   value: "1234" // the guid of the owner, which is a Person entity
 }, null, function(mxobjs, count) {
   console.log("There are " + count + "pets referring to owner 1234");
 });

 mx.data.getSlice("MyFirstModule.Pet", [{
   attribute: "Name",
   operator: "contains",
   value: "ed"
 }, {
   attribute: "Age",
   operator: "greaterThan",
   value: 2
 }], {
   offset: 15,
   limit: 5,
   sort: [["Name", "asc"], ["Age", "desc"]]
 }, function(mxobjs, count) {
   console.log("Pets that matched your filter: " + mxobjs.length);
   console.log("Pets that matched your query: " + count);
 }, function(e) {
   console.error("An error occured: " + e.message);
 });
answered
2

Good question! In offline mode, you don't have access to requests using xpath, as the local sqlite database doesn't support that type of querying. At the moment, offline is still in beta so we don't have any documented APIs for querying sets of data (the normal get by id APIs should work fine)

I'll see if I can find someone to post an example of an internal API that you could use temporarily until we finalize everything in Mendix 7.

answered