Array Issue

2753
11
Jump to solution
09-10-2015 12:31 PM
TerryGustafson
Occasional Contributor II

I'm a novice at js.  have the following js code I'm have an issue with.  I get the following error "Unable to get property 'toFixed' of undefined or null reference"

Here is the code. I was trying to add line 13 to return a second set of results from the LRM_DC_RM_MI1 table.  When I add break points through the console it appears to return the correct values.  Any idea what I'm doing wrong.


function (jobInfo) {

this.gp.getResultData(jobInfo.jobId, "LRM_DR1", lang.hitch(this, this.renderResult));

this.gp.getResultData(jobInfo.jobId, "LRM_DC_RM_MI1", lang.hitch(this, this.renderResult));

function (result) {

this.shelter.hide();

var resultArray = result.value.features;

var resultString = '<table class="test"><tr><td>Route</td><td>Accumulated Mileage</td></tr>';

if (resultArray.length > 0) {

//loop through and populate table


for (var i = 0; i < resultArray.length; i++) {

'<tr><td>' + resultArray.attributes.RID + '</td><td>' + resultArray.attributes.MEAS.toFixed(3) + '</td></tr>';

'<tr><td>' + resultArray.attributes.ROUTE + '</td><td>' + resultArray.attributes.OFFSETtoFixed(3) + '</td></tr>';

'</table>';

else {

//Return No results message


"No result Returned please click on Route";

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Terry,

  Here is your widget back with comments and corrections. I also did some work on the presentation to make it look more like a OTB esri widget. Be sure to overwrite all your files with these and not just the Widget.js

View solution in original post

11 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Terry,

Line 22 thru 26 looks suspicious. You are writing some strings but never setting then to any var, so they are worthless.

then line 24

'<tr><td>' + resultArray.attributes.ROUTE + '</td><td>' + resultArray.attributes.OFFSETtoFixed(3) + '</td></tr>';

                                                                                            ^MISSING DOT

TerryGustafson
Occasional Contributor II

well I added line 05 to pull in the reference Marker information from the gp service.  Then I added line 24 with the attributes from the LRM_DC_RM_MI1 table.  Before I added those 2 lines I had it working and would return the following result.  I was wanting to return the RM information as well.  I guess I could do another array and table.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Terry,

   You are trying to have both getResultData use the same renderResult function?.. How are you differentiating between the results? Both result don't have the same fields do they...?

I can not make much sense of the posted code can you attach your widget?

0 Kudos
TerryGustafson
Occasional Contributor II

I commented out lines 162 and 178 that I added.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Terry,

  Here is your widget back with comments and corrections. I also did some work on the presentation to make it look more like a OTB esri widget. Be sure to overwrite all your files with these and not just the Widget.js

View solution in original post

TerryGustafson
Occasional Contributor II

Robert,

I changed this a little as I wanted to have a separate header for each return result.  My problem is that the way it returns the tables is never consistent.  Which ever one finishes first gets displayed first.  any idea how to fix this?

Here are my changes.

function (jobInfo) {

var jobNames = Object.keys(jobInfo.results);

this, function (name, index) {

this.gp.getResultData(jobInfo.jobId, name, lang.hitch(this, this.renderResult, name));

function (name, result) {

//this.shelter.hide();


var resultArray = result.value.features;

if (name === "LRM_DR1") {

this.resultString += '<table class="test"><tr><th>Corridor and Roadbed</th><th>Accum. Mileage</th></tr>';

else if (name === "LRM_DC_RM_MI1"){

this.resultString += '<table class="test"><tr><th>Route_RM</th><th>RM Offset</th></tr>';

if (resultArray.length > 0) {

//loop through and populate table


for (var i = 0; i < resultArray.length; i++) {

if (name === "LRM_DR1") {

this.resultString += '<tr><td>' + resultArray.attributes.RID + '</td><td>' +

'</td></tr>';

else if (name === "LRM_DC_RM_MI1") {                          

this.resultString += '<tr><td>' + resultArray.attributes.Route + '</td><td>' +

'</td></tr>';

this.resultString += '</table>';

else {

//Return No results message


this.resultString = "No result Returned please click on Route";

var div;

this.shelter.hide();

if (GLOBE.wkid === 4326) {

"resultDiv");

this.resultString;

else if (GLOBE.wkid === 32100) {

"stplmDiv");

this.resultString;

else if (GLOBE.wkid === 102700) {

"stplfDiv");

this.resultString;

else {

'resultDiv');

this.resultString;

if (GLOBE.wkid !== 102100) {

var outSR = new SpatialReference(102100);

this.gsvc.project([GLOBE.evt], outSR, function (projectPoints) {

var pt = projectPoints[0];

var point = new Point(pt);

var newGraphic = new Graphic(point, GLOBE.pointSymbol);

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Terry,

   If you want two different tables then you need to move away from the current one renderresults function handler and separate it into two different functions. That way you define the the whole table placement and header content based on the result name.

0 Kudos
TerryGustafson
Occasional Contributor II

It just seems like since my GP service is returning all of the data I should be able to tell it where to show the data and in what order. I’m trying to get my mind around why sometimes it returns that data correctly and others the order is changed.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Terry,

   This is just the nature of asynchronous code. You would be better off focusing on my last suggestion.

0 Kudos