mx.data.create object seems to disappear

2
Hi. I am trying to use the mx.data.create command in the client api and am having trouble with the result. The create seems to be successful as the following will output to the console that the object was created on the sever and an object is output with a guid and everything looks fine. mx.data.create({ entity: "ContactUs.Service", callback: function(obj) { console.log("Object created on server", obj); }, error: function(e) { console.error("Could not commit object:", e); } }); However if I then look if it exists on the sever I don’t see it on my datagrid view for that type of entity and if I try the mx.data.get with the guid of the supposed created object I get a null returned rather than the object. If I try mx.data.commit on the object I get a 560 error. I don’t understand why the object doesn’t seem to exist when the mx.data.create command says it’s successful and seems to return an object. What am I doing wrong? Thanks.
asked
1 answers
3

Could this be a security issue? Have you checked there are permissions to create the entity and set the attributes?
 

I’ve not been able to recreate the issue you’re seeing. The following works for me.

I created a blank app in 7.22.2, added a module “ContactUs”, with an Entity “Service”, with an attribute “Name”. I also created overview pages to see what was going on.

The following JavaScript run in a console successfully creates a new Service entity with the Name attribute set to “Rob”.

mx.data.create({
    entity: "ContactUs.Service",
    callback: function(obj) {
        console.log("Object created on server", obj);
        obj.set("Name", "Rob");
        mx.data.commit({
            mxobj: obj,
            callback: function() {
                console.log("Object committed");
            },
            error: function(e) {
                console.log("Could not commit object: ", e);
            }
        });
    },
    error: function(e) {
        console.error("Could not commit object:", e);
    }
});

I can see this entity show up correctly in the Overview pages.

I can also retrieve it using it’s GUID (found by watching the console on the Overview page load).

mx.data.get({
    guid: "6755399441055745",
    callback: function(obj) {
        console.log("Received MxObject with GUID " + obj.getGuid());
    }
});

Hope this helps.

answered