Javascript Snippet: Commit Error Code 560

2
Hey all, I'm having an issue creating and committing mxobjects within my javascript snippet. If i create an object, then commit it with these functions: 1.) mx.data.create({ entity: "MyFirstModule.Score", callback: function(obj) { console.log("Object created on server"); tempMxobj = obj; gameId = "" + obj["_guid"]; gameObject = obj["jsonData"]; }, error: function(e) { console.log("an error occured: " + e); } }); 2.) mx.data.commit({ mxobj: tempMxobj, callback: function(mxobj) { console.log("Object committed: " + mxobj); }, error: function(e) { console.log("Error occurred attempting to commit: " + e); } }); I don't have any issues.   However, when I try to alter the newly created object in anyway and then commit it, I get an HTTP 560 error. Here is the code I'm using: 1.) tempMxobj["jsonData"]["attributes"]["Points"] = "3"; mx.data.commit({ mxobj: tempMxobj, callback: function(mxobj) { console.log("Object committed: " + mxobj); }, error: function(e) { console.log("Error occurred attempting to commit: " + e); } }); *I have tried changing the the "3" to 3 to see if the error is due to the variable type. It doesn't affect the result* *Also I have tried to use the tempMxobj.set("Points", 3) function and that doesn't seem to change anything* And finally, here is the HTTP request payload for the commit: 1.) {"action":"commit","params":{"guids":["6755399441059155"]},"changes":{},"objects":[{"objectType":"MyFirstModule.Score","guid":"6755399441059155","hash":"S9qEmClnHhLez63bFEGiUEASV+gWMPr3ztAEAX4XHdA=","attributes":{"Points":"3"}}],"context":[],"profiledata":{"1511371020510-7":10}}   If anyone can point me in the right direction to resolve this issue I would really appreciate it. This feature isn't big enough to develop a fully fledged widget so I'd like to try to build this out in the Javascript/HTML snippet.
asked
2 answers
7

You should always use the client API.

gameId = obj.getGuid();

is the correct way to get your ID.

It is the correct way to set an attribute by using 

tempMxobj.set("Points", 3);

This does set the Attribute on this object. I have a feeling (but I'd have to check with R&D) that the MxObject will keep the hash in sync with the contents of your object. If you try to set an attribute using your method (which is quite... let's say... dirty), the hash is not recalculated and will result in a 'corrupt' Mendix Object, that the Modeler does not accept. (Again, I am not sure, but that's my wild guess).

As Fabian points out, you might not have write permissions.

 

Lastly, a 560 is a server error. This means you should be able to see a stacktrace in your Modeler Console.

answered
4

1. Always use the client api 

2. Might be, that you don't have write permission on the attributes you want to change? (you can check that with .isReadonlyAttr() )

answered