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(),
...
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);
}
});
Thanks to DUC BUI this one is solved see the comments on the last answer. Appearantly you cannot trigger events between pages.