Zum Hauptinhalt gehen

FS_INDEX add Dataset with FS Access API

Kommentare

5 Kommentare

  • Zendesk API User
    Author: StefanSchulz - 8/19/2019 6:49

    Hi Kevin,

    Yep, this is a "simple" casting problem. An ArrayList is no Index, and a Dataset is no Record.

    The correct way would be to fetch the Index stored in "pt_target_page" (there always is one), to create a Record via the Index's API, add the Record and set the Index back to the form field. For creating a Record, you need access to a data stream instance of the DataAccessPlugin being used, which might be a bit more complicated depending on the context your code runs in.

    Cheers,

    Stefan

    0
  • Zendesk API User
    Author: kschork - 8/19/2019 10:13

    Hi Stefan,

    yes your are right. I found the same solution after a few more tries.

    Here is the some example code that works for me. Maybe it is going to help someone in the future.

    ---

    Index globalPageRefTargetIndex = (Index) globalPageRefPageFormData.get(language, "pt_target_page").get();

    globalPageRefTargetIndex.clear();

       

    Record globalPageRefTargetRecord = globalPageRefTargetIndex.create("{\"schema\":\"master_data\",\"gid\":\"" + globalPageRefTargetDataset.getEntity().getGid() + "\",\"table\":\"target\"}");

    globalPageRefTargetIndex.add(globalPageRefTargetRecord);

    globalPageRefPageFormData.get(language, "pt_target_page").set(globalPageRefTargetIndex);

    globalPageRefPage.setFormData(globalPageRefPageFormData);

    globalPageRefPage.save();

    ---

    Greetings,

    Kevin

    0
  • Zendesk API User
    Author: StefanSchulz - 8/19/2019 10:52

    Hi Kevin,

    Yes, that does work. But you are relying on the format of how the Data Access Plugin stores an index. That might change and your code will be broken.

    Better to get hold of the Plugin, fetch a data access session (not a stream, as I wrongfully mentioned earlier), and use its API to get the identifier. For example, the DatasetDataAccessPlugin provided by e-Spirit does understand a Dataset instance.

    I think, one way to get hold of a session is via the form definition provided by the form data container.

    Cheers,

    Stefan

    0
  • Zendesk API User
    Author: mbergmann - 8/19/2019 12:18

    Hi Kevin,

    maybe this code is helpful:

    Index globalPageRefTargetIndex = (Index) globalPageRefPageFormData.get(language, "pt_target_page").get();

    globalPageRefTargetIndex.clear();

    //your code

    //Record globalPageRefTargetRecord = globalPageRefTargetIndex.create("{\"schema\":\"master_data\",\"gid\":\"" + globalPageRefTargetDataset.getEntity().getGid() + "\",\"table\":\"target\"}");

    //better solution to create a record

    GomIndex gomIndex = (GomIndex) globalPageRefPageFormData.getForm().findEditor("pt_target_page");

    //context: a SpecialistsBroker instance, should be available from somewhere

    DataAccessSession<Dataset> dataAccessSession = gomIndex.source().createSession(context, false);

    String identifier = dataAccessSession.getIdentifier(globalPageRefTargetDataset);

    Record globalPageRefTargetRecord = globalPageRefTargetIndex.create(identifier);

    //your code continued

    globalPageRefTargetIndex.add(globalPageRefTargetRecord);

    globalPageRefPageFormData.get(language, "pt_target_page").set(globalPageRefTargetIndex);

    globalPageRefPage.setFormData(globalPageRefPageFormData);

    globalPageRefPage.save();

    Michael

    0
  • Zendesk API User
    Author: kschork - 8/21/2019 9:22

    Thank you very much Michael,

    This code is very helpful indeed.

    Works like a charm.

    Greetings

    Kevin

    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.