I was using JS 3.x to add and update data. I am working on convert my applications to JS 4.x. I had a script that used "dojo/Deferred". Here is the code:
function _applyAdds (featureLayer, propertiesArr)
{
var defer;
require (['esri/graphic', "dojo/Deferred"], function (Graphic, Deferred)
{
defer = new Deferred ();
var graphicsArr = [];
propertiesArr.forEach (function (properties)
{
graphicsArr.push (new Graphic (null, null, properties));
});
featureLayer.applyEdits (
graphicsArr, null, null,
function (a, u, d)
{
console.log (a, u, d);
defer.resolve ();
}, // callback
function (error)
{
console.log ('ERROR!', error);
}// errorback
);
});
return defer.promise;
}
//begin adding new employee assignment
function assignEmployee ()
{
var addEmployee = {};
addEmployee.SPACEKEY = document.getElementById ('EmployeeSpaceID').value;
addEmployee.EMPLOYEEKEY = document.getElementById ('EmployeeID').value;
console.log (addEmployee);
_applyAdds (roomAssinmentTable, [addEmployee]).then (function ()
{
console.log ("Add Employee");
});
}
How do i make this work in JS 4.x?
Thank you in advance for any help on this.
Solved! Go to Solution.
Joel,
Howdy. I seem to have gotten a little farther with this. I am not getting the netowrk error. I can see the Payload tab. However, the data doesnt update in the database. I have tried your method of code and it looks like it works. see screenshot network6.png.
I also tried this code:
function batchEditRoomData ()
{
console.log (roomEditData);
const updates = [];
updates.push ({
attributes: {
objectIds: Number (roomEditData),
PHYSICALCAPACITY: document.getElementById ('editroomDetails-PHYSICALCAPACITY').value
}
});
console.log (updates);
roomsUseLayer.applyEdits ({
updateFeatures: updates
}).then (function (editsResult)
{
// Check if edits were applied successfully
if (editsResult.updateFeatureResults.length > 0) {
console.log ("Features updated successfully.");
$ ('#editMuiltipleRoomsWindow').jqxWindow ('close');
} else {
console.error ("Error updating features:", editsResult);
}
});
}
It looks like it works as well but also data is not updated even though it looks like it did. See attachment network5.png
Do you see anything i may be missing here?
It looks like "roomEditData" is an array of objectIDs. In that case, you'd want something like this instead of what you presently have on lines 4-10:
const updates = [];
roomEditData.forEach(function(oid) {
updates.push ({
attributes: {
OBJECTID: oid,
PHYSICALCAPACITY: document.getElementById ('editroomDetails-PHYSICALCAPACITY').value
}
});
});
That assumes that the OID field name for the layer is actually "OBJECTID". If it isn't, you'll need to change the field name on line 5.
Joel,
You are amazing and a genius! That worked perfectly. That was one of the last pieces of the puzzle. Thank you!