Select to view content in your preferred language

S123 Pulldata from Repeat to Main using javascript

491
2
11-02-2023 12:06 PM
SpatialSean
New Contributor III

I have a repeat that collects several rounds of information that is then passed into the main layer to provide current information using  a JavaScript function.

The issue I am having is that the calculation is not running unless I add another blank record to the repeat.  I've tried adding calculationMode=always in bind::esri:parameters but it could be an error in the script

I created one I can share here attached.  Using this in S123 WebApp for data entry, created in S123 Connect  3.15.165

FYI for anyone looking at this in the future, using the Join with a ',' causes an error in the script hence why you'll see I am using a +

 

function getFirstNonNullValue(vals,separator,reverse) {
    let repeat = vals.split(separator);
	if (reverse == 'true'){
		for (let i = repeat.length-2;i >= 0; i--){
			let val = repeat[i];
			if (val != null && val.trim().length != 0){
    			return val;
			}
		}
	}
	else {
		for (let i = 0;i <= repeat.length-1; i++){
			let val = repeat[i];
			if (val != null && val.trim().length != 0){
    			return val;
			}
		}
	}
}

function getMergedValues(vals,separator,reverse) {
    let repeat = vals.split(separator);
    let mergedVals = '';
    if (reverse == 'true'){
		for (let i = repeat.length-2;i >= 0; i--){
			let val = repeat[i];
			if (val != null && val.trim().length != 0) {
            	mergedVals = mergedVals + repeat[i];
            	mergedVals = mergedVals + '\n------\n';
			}	
        }
    }
    else {
        for (let i = 0;i <= repeat.length-1; i++){
            let val = repeat[i];
			if (val != null && val.trim().length != 0) {
            	mergedVals = mergedVals + repeat[i];
            	mergedVals = mergedVals + '\n------\n';
			}	
        }
    }

    return mergedVals;
}

 

Information is entered into repeat:

 

Information enteredInformation entered

 

 

 

 

 

 

 

Populated after adding second record:

Populated after adding next recordPopulated after adding next record

0 Kudos
2 Replies
ZacharySutherby
Esri Regular Contributor

Hello @SpatialSean

You don't need to use a JavaScript function you can use the indexed-repeat() function to do this. Something like the following should work: 

indexed-repeat(${Capture_Info}, ${rpt_Info},count(${Capture_Info}))

Thank you,
Zach
0 Kudos
SpatialSean
New Contributor III

Unfortunately it is not as simple as my example posted above.  There are multiple questions within the repeat - some of which remain blank and when using indexed repeat it will pull the null values.

0 Kudos