oldValue reset after update?

Hi

Thought I had finished for the night but seemingly not :slight_smile:

I am updating via a WSDL web service. I am building oldValues into my update “data” array to comply with the update method on the web service. All is well and the update occurs. If I then change another value in the SC application and then call update again, it seems that oldValues has not been reset after the previous update and I get a 500 server error because of a concurrency conflict.

Should oldValues become auto-updated after successive updates?

Thanks.

callOperation() is a low-level method that just sends whatever data you pass it. It has no information about components or already loaded datasets and can’t update them. If you’re expecting cache synchronization behavior and awareness of databinding, go through the DataSource.

I am going through the DataSource on this occasion. Not touching callOperation.

Played around with this over the weekend. Still no joy with oldValues.

FYI, the scenario here is as follows:-

A datasource talking to a WSDL webservice using standard wsOperation(s) (no callOperation() involved).
A DynamicForm using the datasource (specified above) and an initial call to the form’s fetchData() method.
The web service returns a single record.
Initial changes are made to the data in the form.
The oldValues data is correct on the very first update.
On any subsequent changes to the form’s data, oldValues is not updated causing bogus optimistic concurrency errors on the server.

A code sample of the above is shown below. FYI, in the sample code, I have added some additional code to handle “oldVals”.

Can you clarify whether in the circumstances described, oldValues should be updated after each subsequent update back to the webservice? If so, kindly let me know what, if anything, I am doing wrong.

Thanks.

// Base sms DataSource class			
// Custom "oldVals" support added
isc.defineClass("SmsDS", "DataSource").addProperties({ oldVals: [] });

 isc.SmsDS.create({
 		ID: "standDS",
		xmlNamespaces : { sms : "urn:sms.stand" },
		recordXPath: "//sms:StandData/sms:CurrentStand",
		serviceNamespace: "urn:sms.stand",
	 	operationBindings: [
	 		{ operationType: "fetch", wsOperation: "Fill" },
			{ operationType: "update", wsOperation: "Update" }],
		fields: [
			{ name: "StandId", title: "Stand Id", primaryKey: "true", hidden: true},
			{ name: "StandName", title: "Stand Name"},
			{ name: "StandLocation", title: "Stand Location"},
			{ name: "StandCode", title: "Stand Code"},
			{ name: "AddId", title: "Address Id", hidden: true},
			{ name: "StandPhone", title: "Stand Phone"},
			{ name: "StandFax", title: "Stand Fax"},
			{ name: "StandEmail", title: "Stand Email"} 
			],
		transformRequest: function(dsRequest){
			if (dsRequest.operationType == "update") {
				var orig = isc.addProperties( {}, standDS.oldVals );
				var curr = isc.addProperties( {}, dsRequest.data);
				var stan = { OriginalStand: orig, CurrentStand: curr };
				var structure = {
					stand: {
						StandData: stan
					}
				}
				dsRequest.data = structure;
			}
			
			return dsRequest.data;
		}});

isc.DynamicForm.create({
    ID: "standForm",
    dataSource: standDS,
    autoDraw: false,
    width: 250,
    fields: [
	{ name: "StandName" }, 
	{ name: "StandLocation" },
	{ name: "StandCode" },
	{ name: "StandPhone" },
	{ name: "StandFax" },
	{ name: "StandEmail" },
	{
        name: "saveBtn",
        title: "Save",
		colSpan: 2,
		align: "right",
		startRow: true,
        type: "button",
        click: function() {

		standForm.saveData(function (dsResponse, data, dsRequest) {
				// Custom "oldVals" support added
				standDS.oldVals = data },
				{ useHttpProxy: true });
        }
    }]
});
	
standForm.fetchData(null, function(dsResponse, data, dsRequest) {
	// Custom "oldVals" support added
	standDS.oldVals = data[0] },
	{ useHttpProxy: true } );
	
isc.HLayout.create({
            showEdges:true,
            height:250, membersMargin:5,  layoutMargin:10,
            members:[
				standForm
            ]
        })

In your callback from form.saveData() call one of the following: form.editRecord(data), form.setValues(data) or form.rememberValues(). I use editRecord so that any data the server may have filled in is now displayed.

Hi David - thanks for the heads-up. Are you saying that calling form.editRecord() will actually re-sync the “oldValues” property that is provided on DSRequest object at the next update?

This is the root of my question/problem. After the initial fetch and first update, the oldValues on the DSRequest object does not change, despite the fact that changes are made and committed to the server through the DataSource->WebService.

Thanks.

Well, the editRecord call will push the field data into the form fields and reset the oldValues such that the next call to saveData will now be based on those passed during the editRecord call. I don’t use the WSDL-based data sources so I’m not sure you receive updated data back from the save call. If not, you can call the rememberValues method to tell the form that the field values have been saved and to reset the oldValues passed on the next save.

In general, the oldValues is just the value of the fields as last set during an editRecord/editNewRecord or setValues call. Changes on the form are detected by comparing these saved values to the current ones. Both oldValues and the current field values are then passed to the data source for the add or update operation. By default, if the server returns data as part of the response, fields are updated individually on the form if they haven’t been changed already. But the oldValues are not reset so only further changes from the original fetch would report as changed (form.valuesHaveChanged()).

Hope this helps.
dave

Yesss!!! - editRecord() is the bad-boy :slight_smile:

It gives me exactly what I wanted using the “data” parameter in the callback from saveData().

I remembered that I had originally looked at editRecord() but took the documents too literally. The argument to editRecord is of type “ListGridRecord” so, I assumed that was only to be used when the form was being used in conjuction with a grid. My bad!

So, thank you for helping me out with this. I really appreciate it! :slight_smile:

Regards and thanks!

-H