I’m using a RestDataSource and pulling values out for use in a DynamicForm (for display only, using StaticTextItem). The data source is subclassed from RestDataSource as follows and only needs to support the fetch operation.
isc.defineClass("JSONRestDataSource", "RestDataSource");
isc.JSONRestDataSource.addProperties({
dataFormat:"json",
jsonRecordXPath: "/data",
operationBindings: [ {operationType:"fetch", dataProtocol:"postParams"}]
});
Then we create a data source of type JSONRestDataSource:
isc.JSONRestDataSource.create({
ID:"LOCATION_HEADER",
fields:[
{ name: "CUSTOMER_CLASS", valueXPath: "/SHIP_TO/CUSTOMER_CLASS"},
{ name: "SHIP_TO_NAME", valueXPath: "/SHIP_TO/SHIP_TO_NAME"},
{ name: "ADDRESS", valueXPath: "/SHIP_TO/ADDRESS"},
{ name: "CITY", valueXPath: "/SHIP_TO/CITY"}
],
dataURL:"src/controller.php?m=Utilities&resource=LOCATION_HEADER"
});
Then, we utilize this data in a DynamicForm:
this.shipToDetails = isc.DynamicForm.create({
dataSource: LOCATION_HEADER,
fields:[
{wrap:false, title:"Customer Class", name:"CUSTOMER_CLASS", _constructor:"StaticTextItem"},
{wrap:false, title:"Ship To", name:"SHIP_TO_NAME", _constructor:"StaticTextItem", textBoxStyle: "windowHeaderText"}\
,
{wrap:false, title:"", name:"ADDRESS", _constructor:"StaticTextItem", textBoxStyle: "windowHeaderText"},
{wrap:false, title:"", name:"CITY", _constructor:"StaticTextItem", textBoxStyle: "windowHeaderText"}
],
wrapItemTitles:false,
width: "100%"
});
This allows us to extract various fields from the json structure returned by the server. What confuses me is that there appears to be no way, in the Form, to specify the xpath for the data item. In other words, since we specify the xpath to each field in the DataSource definition (not the Form), we can’t have a BILL_TO/CITY and a SHIP_TO/CITY in the same form. This seems to defeat the beauty of returning a real json structure from the server and being able to use xpath to pull out various fields.
Is there any way to specify, in the Form, the xpath to the value? For example, a way to accomplish this:
isc.JSONRestDataSource.create({
ID:"LOCATION_HEADER",
fields:[
{ name: "/SHIP_TO/CUSTOMER_CLASS", valueXPath: "/SHIP_TO/CUSTOMER_CLASS"},
{ name: "/SHIP_TO/SHIP_TO_NAME", valueXPath: "/SHIP_TO/SHIP_TO_NAME"},
{ name: "/SHIP_TO/ADDRESS", valueXPath: "/SHIP_TO/ADDRESS"},
{ name: "/SHIP_TO/CITY", valueXPath: "/SHIP_TO/CITY"}
],
dataURL:"src/controller.php?m=Utilities&resource=LOCATION_HEADER"
});
Note that we’ve used the xpath value as the field name, to produce uniquely named fields for use in the Form. Now that I’ve written all this out, I suppose it’s a reasonable solution. I’ll post this anyway in case there’s some better practice to doing this type of thing.