Widget update on entity change question

2
I am trying to achieve that my widget receives an update event if any of the records in a specific entity are modified. I created a basic widget which does not much except subscribe to changes and log in the debugger. See here the code: mxui.widget.declare('WidgetTest.TestContext', { //DECLARATION addons : [dijit._Contained], inputargs: { entity: '', entityXPath: '' }, // Global variables dataobject : null, startup : function() { console.log(this.id + ".startup"); }, // Called when the widget is created. postCreate : function(){ console.log(this.id + ".postcreate"); this.startmywidget(); this.actLoaded(); }, refreshWidget: function () { console.log(".refreshWidget"); }, update : function(mxobj, callback) { console.log(this.id + ".update function"); }, startmywidget : function (object) { console.log(this.id + ".startmywidget"); mx.data.subscribe({ entity : this.entity, callback : dojo.hitch(this, this.refreshWidget) }); }, // Here we unsubscribe to our object to clean up. uninitialize : function() { console.log(this.id + ".uninitialize"); }, _setDisabledAttr : function(value) { this.isInactive = !!value; this.domNode.attr("disabled", this.isInactive); } }); When I load the page I see the following log messages: .postcreate .startmywidget .startup .update function I would expect that if I make any changes in one of the records of the entity and save it i would be notified and my refreshWidget method will be triggered which would result in an extra entry in the logger saying: .refreshWidget. However that is not happening and I don't understand why not. So I am asking if some of you can help solving this puzzle? Thanks, Alex
asked
3 answers
1

Entity subscriptions are only triggered rarely: Either when an object form the specified type is created, deleted or when the communityCommons action 'refreshClass' is triggered.

Most likely you want to list to the changes of the specified object, that is:

startmywidget : function (object) {
        console.log(this.id + ".startmywidget");
        mx.data.subscribe({
            guid     : object.getGuid(),
            ...
answered
1

That is not what I want to achieve but is also one of the options I tried. I want to input an entity and get all the entity records. Build my widget on the page with those records and when one of them changes I want to update the widget. But to be clear here is the code for the other option I tried.

Maybe someone can spot the mistake in my way of coding or thinking here.

mxui.widget.declare('WidgetText.TestContext',  {
    //DECLARATION
    addons       : [dijit._Contained], 
    inputargs: {       
        entity: '',
        valueAttr: '',
        labelAttr: '',
        entityXPath: ''
    },

    // Global variables
    dataobject : null,

    startup : function() {
        console.log(this.id + ".startup");
    },

    // Called when the widget is created. 
    postCreate : function(){
        console.log(this.id + ".postcreate");
        this.startmywidget();
        this.actLoaded();
    },

    refreshWidget: function () {
        console.log(".refreshWidget");
    },

    getData : function() {
        console.log(".subscribeData")
        mx.data.get(
            {
                xpath: "//" +  this.entity + this.entityXPath,
                callback: dojo.hitch(this, this.subscribeData)
            });
    },

    subscribeData : function (objArray) {
        console.log(".subscribeData");
        var dataList = [];

        for(var i = 0; i < objArray.length; i++) {
            var object = objArray[i];
            dataList[i] = { label: object.get(this.labelAttr), data: parseFloat(object.get(this.valueAttr)) };

            this.subscribe({
                guid     : object.getGuid(),
                callback : dojo.hitch(this, this.refreshWidget)
            });
        }
        console.debug(objArray);
    },

    update : function(mxobj, callback) {
        console.log(this.id + ".update function");
    },

    startmywidget : function (object) {
        console.log(this.id + ".startmywidget");
        this.getData();
    },
    // Here we unsubscribe to our object to clean up.
    uninitialize : function() {
        console.log(this.id + ".uninitialize");
        logger.debug(this.id + ".uninitialize");
    },

    _setDisabledAttr : function(value) {
        this.isInactive = !!value;
        this.domNode.attr("disabled", this.isInactive);
    }
});
answered
0

Thanks to DUC BUI this one is solved see the comments on the last answer. Appearantly you cannot trigger events between pages.

answered