2 Replies Latest reply on May 5, 2014 7:14 AM by Mark Ross

    How to use objectNotification with javascript models

    Mark Ross

      I'm currently trying to implement setObjectNotification() and addObjectNotification() in my app.  I'm using pure javascript models.  Here's what I have in my code, but I never seem to get notified:


      Rho.RhoConnectClient.addObjectNotify('MyModel', mymodel.id);
      function modelSynced(params) {
       console.log('synced params: ' + params);



      The modelSynced function never gets called and I dont know why.  The documentation (Rhomobile | RhoConnectClient) refers to Ruby's application.rb for setObjectNotifcation(), but since I'm not using Ruby models, I assumed this wouldnt work.


      My overarching goal is to create MyModel, sync with the server, get the ID (from the server) for the newly created MyModel and store that ID with another model I need to create (parent-child type link).  Any help on why the above doesnt work or another way to tackle this problem would be much appreciated.  I've been struggling with this for some time now.


      Windows 7 64bit, Rho 4.1.1, Android Nexus 10 running 4.4.2

        • Re: How to use objectNotification with javascript models

          addObjectNotify is used to get the notifications about specific model's object, not the model itself. For example:


          obj1 = Model.create(...)

          Rho.RhoConnectClient.addObjectNotify('Model', obj1.id)


          if you want to get model notifications, you should use setModelNotification

          Rhomobile | RhoConnect.js API Reference


          Model is not an "object" (in this context) , model is the "class definition" for the model's objects. You define the model, then you create objects (instances) of that model.


            • Re: How to use objectNotification with javascript models
              Mark Ross



              I think I chose bad variable names in my quick example code.  I do want to get notified when an object (an instantiation of the model) is synced with the RhoConnect server.


              I'll try to use more correct names in explaining what I am trying to accomplish. 


              1. Create an object of a model on a page (model = Incident, object = newIncident)
              2. Set and save attributes of that object (name = 'test', description = 'my test', etc...)
              3. Capture a photo from the device's camera
              4. Save photo (model = Media, object = newMedia)
              5. Sync newIncident object with the backend which should return a new incident.id (from backend database)
              6. Store incident.id in newMedia object
              7. Sync newMedia object with the backend


              So I need to first create the incident, get the id and store that id with the photo that was captured.  I assume for all of that, I need to be listening for a specific object sync change and not an entire model.