Select to view content in your preferred language

errots in inspection form when inputting new repeat

540
3
Jump to solution
01-05-2024 07:48 AM
clt_cabq
Frequent Contributor

I have a form based on the Hydrants Inspection sample form that I've modified for my use case. The form seems to work fine for newly collected locations. However, I've populated the layer with existing locations that supply data to the main table but the related 'repeat' table contains no data. When I try to collect data for one of these 'preloaded' locations in the repeat for the inspection i get the following error:

@javascript error:TypeError: Cannot read property 'SIG_Det' of undefined in InspectionsFunctions.js:LastDetermination

This is coming from fields that use the following calculation in the form:

string(pulldata("@javascript", "InspectionsFunctions.js","LastDetermination",${CurrInsp}, ${PrevVisit}))

Script in the form that is causing an error is below. Data in the related (repeat) table get populated correctly. I am wondering if the error stems from there not being an existing value since line 3 of the javascript performs when there is a record in the repeat section but there is no 'else' to handle when (CurrInsp.length ==0).

function LastDetermination(CurrInsp,maxDate){

	if (CurrInsp.length>0) {
		var maxDateInspections = CurrInsp.filter(item => item.InspDate === maxDate);
		var countOfInspectionsWithMaxDate = CurrInsp.filter(item => item.InspDate === maxDate).length;
		var detOfMaxDate = maxDateInspections[countOfInspectionsWithMaxDate-1].SIG_Det;
		return detOfMaxDate
	}
}

 

0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Esteemed Contributor

I wonder if CurrInsp is a null object in that case?  At least in Python you can't call anything on a null object so you would instead do just if CurrInsp which basically checks if it is null object.  Maybe try that or both like if CurrInsp and CurrInsp.length > 0?

Just an idea

View solution in original post

0 Kudos
3 Replies
DougBrowning
MVP Esteemed Contributor

I wonder if CurrInsp is a null object in that case?  At least in Python you can't call anything on a null object so you would instead do just if CurrInsp which basically checks if it is null object.  Maybe try that or both like if CurrInsp and CurrInsp.length > 0?

Just an idea

0 Kudos
clt_cabq
Frequent Contributor

Thanks @DougBrowning  - that may be the case, I will give that a shot and see. 

clt_cabq
Frequent Contributor

removing the 'if' statement seems to correct the problem. however that is there to pull in values from the previous inspection for field staff to view as they are completing their inspection, so I may have to work in an 'else' option. Thanks for the nudge!