AnsweredAssumed Answered

How to consume the data in a function from the fetchData method?

Question asked by owenmt8656 on Dec 20, 2017
Latest reply on Dec 20, 2017 by owenmt8656

I'm using the Enhanced Search widget to pass a value from a feature using the publishData method to another widget.

 

Sending Widget:

        this.publishData({
          data: feature.attributes["PARID"],

         keepHistory: true

  })

I'm using the onReceiveData function in the other widget to grab the data. If I write to the console under this function it gets the value, but when I try to consume it in a different function it doesn't retun the data. I've tried setting it to a global variable and still nothing. I have no idea what is wrong:

 

Receiving widget:


startup: function() {
this.inherited(arguments);
this.fetchDataByName('eSearch');

//console.log('startup');
},

onReceiveData: function(name, widgetId, data, historyData) {
//filter out messages
if(name !== 'eSearch'){
return;
}
window.ParcelData = data;

console.log(ParcelData);                <THIS WORKS>
},
onOpen: function(){
console.log('onOpen');
require(["dijit/layout/TabContainer", "dijit/layout/ContentPane", "dojo/domReady!"], function(TabContainer, ContentPane){

var tc = new TabContainer({
style: "height: 100%; width: 100%;"
}, "tc1-prog");

var cp1 = new ContentPane({
title: "Parcel Info",
content: "<div id='parcelPropInfo'></div>"
});

tc.addChild(cp1);

var cp2 = new ContentPane({
title: "Building Info",
content: "<div id='parcelBldgInfo'></div>"
});

tc.addChild(cp2);
tc.startup();
});

// parcelPropInfo
dojo.ready(function(){
// Look up the node we'll stick the text under.
var targetNode = dojo.byId("parcelPropInfo");

// The parameters to pass to xhrGet, the url, how to handle it, and the callbacks.
var xhrArgs = {
//url: "./widgets/Demo/resources/parcelPropInfo.aspx?parid=A02000200230000400",
url: "./widgets/Demo/resources/parcelPropInfo.aspx?parid=" + ParcelData,  <THIS DOES NOT>
handleAs: "text",
load: function(data){
// Replace newlines with nice HTML tags.
//data = data.replace(/\n/g, "<br>");

// Replace tabs with spaces.
//data = data.replace(/\t/g, "   ");

targetNode.innerHTML = data;
//return data;
},

error: function(error){
targetNode.innerHTML = "An unexpected error occurred: " + error;
//return "An unexpected error occurred: " + error;
}
}

 

Any help would be appreciated

Thanks

Outcomes