2

I have two related tables. This is a relationship where parent can have zero or many notes. I am trying to save a note that's related to original record. Code itself is

  app.datasources.RadiosManualSave.load(function() {
    ...
    var existingRecord = app.datasources.RadiosManualSave.item;
    ... // update some fields of the existingRecord & save later
    try {
      app.datasources.RadiosManualSave.saveChanges(function() {

        var notesCreate = app.datasources.RadioNotes.modes.create ;  
        var newNote = notesCreate.item ;
        newNote.Notes = tempRecord.Notes ;
        //newNote.Radios_fk = existingRecord.Id ;
        newNote.Radios = existingRecord ;

        notesCreate.createItem(function() {
          app.showPage(app.pages.Radios);  
        });
      });  
   } catch(e) {
        showSnackbar('Error saving record');
        app.datasources.RadiosManualSave.clearChanges();
   }
   ...
}

The code fails when I associate the note with the existing record.

The error message is:

Can't associate draft record with record in draft datasource.

However existing record is not in draft datasource and is already in the table. Assigning to the foreign key works without problems.

Kos
  • 4,890
  • 9
  • 38
  • 42
work monitored
  • 431
  • 6
  • 17
  • Could you maybe clarify where existingRecord comes from or where the variable is declared? Also in client side code that has a success or failure dependency I would suggest using .saveChanges({success: function() {}, failure: function() {}); instead of try/catch. – Markus Malessa Jan 22 '19 at 22:07
  • 1
    Agreed, I can change to success or failure and will give it a try but I have a suspicion I will still get the same error. It would be nice if App Maker documented possible errors and reasons for it, rather than having people trying to guess it. Finally I am not a fan of the relations api since it looses some of the flexibility of using foreign keys, especially if the back end is relational. – work monitored Jan 23 '19 at 00:17

1 Answers1

0

I had a similar issue where I had two related tables i.e. Employee and Attendance. Employee could have many Attendance. So when creating an Attendance I had to specify the Employee. On selecting the Employee from drop-down to associate it with Attendance, there would be the same error saying:

Can't associate draft record with record in draft datasource.

Nothing really actually worked. Going through the documentation I found some information about draft records Draft Record

So setting my parent datasource(Employee) to automatic save mode actually did the work.

  • In my case, it worked then it did not work... Not sure what was going on. I pushed to the back burner, when I came back to it, it started working on. Possible, I wiped out by custom database couple times but I am guessing it was bug that caused the code to not compile.... – work monitored Jun 03 '19 at 13:35