Fill out 1 survey, autofill and create multiple features

229
1
Jump to solution
02-26-2024 08:13 AM
KellyTaylor
New Contributor III

hey all,

I work for a utility company and I'm building a survey where the user enters data about a leak and a work order to repair the leak. "Leaks" being the primary layer, and "Work_Orders" being a repeat. What I'm trying to do is have the user fill in a single work order (WO) while automatically creating 2 WOs. The first WO has a wo_type of either "service_leak" or "main_leak". I'd like the second WO to autofill all the same values except the wo_type would now be "recheck"

My instinct is to use indexed-repeat() but I may be misunderstanding how to use it. In the calculation column for the "wo_type" field I've put indexed-repeat(${wo_type}, ${Work_Orders}, 1). It comes back with a cycle dependency error.

Is there another way to achieve this?

Thanks in advance!

 

Tags (1)
1 Solution

Accepted Solutions
KellyTaylor
New Contributor III

if anyone stumbles upon this and is struggling to do the same thing, I finally found a solution here.

Here's my javascript function:

function getValue(position, repeat, field) {
	if (position == 2){
		return repeat[0][field]	
	}
}

 and here's what I put in the calculation column in the xlsform:

pulldata("@javascript", "functions.js", "getValue", position(..), ${Work_Orders}, 'premise' )

with Work_Orders being the name of the repeat, and premise being the name of the field I'm copying over.

I had to put this in a null field called 'premise_null' and then set the 'premise' calculation to ${premise_null} in order to avoid yet another cycle dependency error 🤔

It's probably not ideal if you have a lot of fields to carry over because it'd need to run the .js for each field. If this was an issue for me, I'd write a js function that would return all the necessary fields in an array, store that in a null field in the xlsform, and then access each item in the array using calculations.

Good luck to anyone trying to do this! It took me forever to finally find a solution. It would be lovely if indexed-repeat could refer to earlier entries of the same field without a cycle dependency error.

View solution in original post

0 Kudos
1 Reply
KellyTaylor
New Contributor III

if anyone stumbles upon this and is struggling to do the same thing, I finally found a solution here.

Here's my javascript function:

function getValue(position, repeat, field) {
	if (position == 2){
		return repeat[0][field]	
	}
}

 and here's what I put in the calculation column in the xlsform:

pulldata("@javascript", "functions.js", "getValue", position(..), ${Work_Orders}, 'premise' )

with Work_Orders being the name of the repeat, and premise being the name of the field I'm copying over.

I had to put this in a null field called 'premise_null' and then set the 'premise' calculation to ${premise_null} in order to avoid yet another cycle dependency error 🤔

It's probably not ideal if you have a lot of fields to carry over because it'd need to run the .js for each field. If this was an issue for me, I'd write a js function that would return all the necessary fields in an array, store that in a null field in the xlsform, and then access each item in the array using calculations.

Good luck to anyone trying to do this! It took me forever to finally find a solution. It would be lovely if indexed-repeat could refer to earlier entries of the same field without a cycle dependency error.

0 Kudos