JSDO Record Creation

Posted by spandau66 on 18-May-2016 06:44

I'm attempting to create a new record, but when the record is passed across to the back End, I see the following error:
Error parsing JSON: unexpected token: string. (15360)

Now to elaborate:
(Deletions, Modifications all work fine).

The following is based on a Kendo Grid being populated with a JSDO Datasource.

The issue is with the JSDO JSRecord construct being passed to the back end.

Using the inline editing (Add New) on the Kendo Grid.

The JSRecord construct is as expected and I can successfully create data (as seen below).

{

  • dsCostCodes: 
    {
    • prods:hasChanges: true,
    • eCostCodes: 
      [
      • {
        • prods:rowState: "created",
        • prods:clientId: "1463558559605-1258",
        • Company: 0,
        • CostCode: "18-05",
        • Name: "test",
        • ShortName: "test",
        • AccountStatus: "",
        • Deleted: false,
        • Suspended: false,
        • LedgerType: "",
        • RetainedEarningsCostCode: "",
        • RetainedEarningsExpenseCode: "",
        • NotesKey: "",
        • NonRecVATPercentage: 0,
        • EmailAddress: "",
        • UserList: "",
        • UseInPCR: false,
        • HasAttachments: false,
        • HasContacts: false,
        • HasNotes: false,
        • xlcode4: "",
        • ImportMode: ""
        }
      ]
    }

}

Kendo Grid binding to fields on a Viewer Panel.

The JSRecord construct is as NOT expected and contains the "default" and "fields" definitions (as can be seen below - have removed all entries from "default" and "fields")

{

  • dsCostCodes: 
    {
    • prods:hasChanges: true,
    • eCostCodes: 
      [
      • {
        • prods:rowState: "created",
        • prods:clientId: "1463553648779-1258",
        • Company: 9996,
        • CostCode: "17-05",
        • Name: "17-05",
        • ShortName: "17-05",
        • AccountStatus: "",
        • Deleted: false,
        • Suspended: false,
        • LedgerType: "",
        • RetainedEarningsCostCode: "",
        • RetainedEarningsExpenseCode: "",
        • NotesKey: "",
        • NonRecVATPercentage: 0,
        • EmailAddress: "",
        • UserList: "",
        • UseInPCR: false,
        • HasAttachments: false,
        • HasContacts: false,
        • HasNotes: false,
        • xlcode4: "",
        • ImportMode: "",
        • idField: "_id",
        • _defaultId: ""
        }
      ]
    }

}

It is this construct that is causing the JSON error highlighted above.

When I select my Add Record button, I use the basic code structure 

grid.addRow();

which is then bound to the fields for input. I enter all the relevant fields. In my Save Event, I use the following construct:

var sel = $scope.mainCostGrid.select();
var item = $scope.mainCostGrid.dataItem(sel);
var jsdo = $scope.costCodeGridData.transport.jsdo;
var rec = jsdo.eCostCodes.findById(item._id);

jsdo.autoApplyChanges = false;
jsdo.subscribe('AfterSaveChanges', function callback(jsdo, success, request) {
jsdo.unsubscribe('AfterSaveChanges', callback, jsdo);
if (success) {
if (addingRecord) {
....
}
else {
....
}
}
else {
....
rec.rejectRowChanges();
}
}, jsdo);

if (addingRecord) {
rec = jsdo.eCostCodes.add(item);
} else {
jsdo.eCostCodes.assign(item);
}

jsdo
.saveChanges()
.then(function () {
console.log("after save");
});

I would appreciate suggests on why my JSRecord construct is different and IF I AM doing the above incorrectly...

Martyn

All Replies

Posted by egarcia on 18-May-2016 09:03

Hello Martyn,

Yes, it looks like the presence of "defaults" and "fields" in the JSON structure is what is causing the problem.

I think that the ABL is expecting scalar values and not an object "{}".

Are you using the Views service in Telerik Platform or the Progress Data Service template?

To solve this issue you would need to determine where these properties are coming from.

Do you have these properties as part the "schema" definition in the dataSourceOptions (index.js)?

In practice, for the JSDO DataSource (JSDO dialect), you do not need to specify the "schema" property for the DataSource, the schema is resolved by using the catalog.

A possible workaround would be to remove these properties from the "schema" definition.

Another alternative, would be to ensure that these properties that are unexpected are removed from the request before sending them to the server.

However, it would be important to figure out where they are being added. For that we would need a reproducible case.

You could contact Technical Support and log a bug report.

I hope this helps.

Posted by AdrianJones on 18-May-2016 09:32

> I think that the ABL is expecting scalar values and not an object "{}".

or maybe expecting arrays of objects. might be worth trying wrapping with []...

[{}]

Posted by spandau66 on 18-May-2016 11:06

Hi Ed,

I'm using the JSDO Catalog in all instances.

I have a workaround at the moment in that I create an array object to transfer the values from the NEW Kendo Grid Row and then pass that Array Object into the "jsdo.eCostCodes.add(newItem);". This is working fine using this type of workaround.

However, I am still digging around to ascertain where the "defaults" and "fields" are being pulled from (no luck so far). It's odd in that I use the same mechanism (current selected row) on Modifications and Deletions without issue. It only seems to be on Add Row (grid.addRow) that the extra schema definitions are appearing. As I said I will dig around and attempt to discover the culprit in adding the extra schema definitions.

Once I have more info (or maybe not), I'll log it with Technical Support.

Regards

Martyn

This thread is closed