Select to view content in your preferred language

Auto Create a Repeat Record

815
9
Jump to solution
05-10-2024 10:56 AM
BKS
by
Frequent Contributor

Hello,

Seeking ideas/direction on how to implement the following:

We have a survey with nested repeats.  

We use the INBOX to load the survey and the user can make edits to the related 1st repeat.  

If any edits are done, we would like to automatically create one 2nd repeat record to guide the user to indicate / record what change was implemented (read edit log).  Don't need to automatically define what exactly was changed.  Instead just want to create the 2nd repeat record to allow the user to update what they have changed manually.

Currently this is all working except the user must manually create an edit log record (2nd repeat).  I would like to force this 2nd repeat record to at least be created automatically, knowing that the user can still delete it if they must.  

Your input is most appreciated.

Cheers, BKS

0 Kudos
1 Solution

Accepted Solutions
abureaux
MVP Frequent Contributor

Sounds like you have a good solution there! If you have no more questions, don't forget to mark your response as the accepted solution so others can benefit.

"...IF the parent record has zero associated repeat recs, it automatically creates 2 repeat records the first time..."

Sounds like you need to beef up your calculate a little. On that note, two things:

  • the repeat_count column doesn't always like doing math. A simple solution is to put your calculate in to a calculate field, and then reference that calculate in the repeat_count column. This can help resolve lots of little unforeseen issues.
  • Building on what I have above, use an IF() statement in a separate calculate. Something like this should work:
    if(count(${test_rpt})=0,1,once(count(${test_rpt})+1))
    I had a similar issue with my second attempt and ended up with the blow, which is effectively the same thing:
    abureaux_0-1715782238110.png

     

"I'm hoping that there might be a way to use position(..) and/or index to have the survey open to the last (most recent) repeat record."

This is a common ask. Unfortunately, the answer is "cannot be done" (at least presently).

"...the user is NOT able to delete the newly created repeat record..."

This is expected behaviour. As soon as you use the repeat_count column, the option to add or delete records goes away.

View solution in original post

0 Kudos
9 Replies
jcarlson
MVP Esteemed Contributor

Sounds kind of tricky. I don't know if this would work, but perhaps your survey could use the repeat count feature to manually define the number of repeats. You could use the once function to grab the initial value of the repeat count field, then increment it by 1, put that value in.

I would guess the form will complain about circular dependencies, though. But it's worth trying, I think!

- Josh Carlson
Kendall County GIS
0 Kudos
BKS
by
Frequent Contributor

Thanks for that idea @jcarlson .

Exactly when does the new repeat record in the 2nd nested repeat (i.e. the Edit Log) get created, when I increment the repeat count by 1?  By doing so you think a new repeat record would be created?

Ideally I'd like to create the Edit Log row when any RW value has been changed by the user in the form, BUT as a perhaps simpler alternative, is there a way to create this record as soon as I open the form if I'm doing so to Edit it ? 

Just searching for a reasonable solution; doesn't have to be perfect.  However, it would be nice to have something better than relying on the user to add a repeat record and record the change they made.

Your assistance is appreciated.

BKS

0 Kudos
abureaux
MVP Frequent Contributor

Funny thing is, this actually works without a circular reference! So, this workflow should be fine:

abureaux_0-1715612599903.png

abureaux_1-1715612606870.png

 

jcarlson
MVP Esteemed Contributor

Ah, excellent! It's been a while since I attempted something similar, and I'd been going about it the wrong way. Thanks for actually testing it out!

- Josh Carlson
Kendall County GIS
abureaux
MVP Frequent Contributor

Oh ya. I'll point out the obvious though. This will:

  1. Always leave you with an empty repeat
  2. You cannot have required fields in your repeat since the user would need to fill them out which would create a new repeat (and that would be your circular reference).

So long as you are okay with not having required fields and that empty repeat, this actually works a lot better than I would have expected.

If you add a conditional statement to the formula to swap between "count(${test_rpt})+1" and "count(${test_rpt})+0", then you'd be fine to ignore the above.

abureaux
MVP Frequent Contributor

Because this worked better than I would have expected, it got me thinking of the limitations I mentioned. I put together this alternative quickly that circumvents most of those limitations.

abureaux_0-1715613717130.png

Basically, that ${test_counter} field is the trigger. Just decide what you want a "complete" record to look like and set the logic up according to that. That means you can have required fields!

0 Kudos
BKS
by
Frequent Contributor

Hello @jcarlson and @abureaux and thanks for all your help !

I tried to get either, and even a combination, of your solutions to work for me but I kept getting strange results.  I almost gave up and then I tried this solution:

1) Added once(count(${test_rpt})+1) to the repeat_count column of begin repeat record

2) Added allowAdds=true allowUpdates=false query to the bind::esri:parameters column of begin repeat record

 

This solution produced the following:

1) After loading the survey from the INBOX, 1 additional repeat record (editable since allowAdds=true), was added.

2) It also loads any previous repeat records (read-only since allowUpdates=false query)

3) If I try to save the survey it notifies that I have a required field in the editable repeat record; which is correct.

4) After populating this one and only required field in the repeat, I am able to submit the survey

This creates no blank repeat recs and also allows me to have required fields in the repeat.

 

I've tested this but not exhaustively.  I wonder if there is something you would expect to find given this solution (that perhaps I have not yet found)?

 

One thing I noticed that is odd (and I cannot explain) is that IF the parent record has zero associated repeat recs, it automatically creates 2 repeat records the first time.  BUT after at least one repeat records exists for a given parent record, it only creates 1 additional repeat record when opening.

The other smallish thing is that the repeat that is displayed when the survey is opened is the first repeat created, followed by the next and so on.  To get to the repeat that the user needs to update, they have to click through as many repeat recs as exist.   I realize they can long click on the right arrow to go to the end of the repeat collection, but this is not obvious.  I'm hoping that there might be a way to use position(..) and/or index to have the survey open to the last (most recent) repeat record.

Finally one other small thing that I do not understand, is that the user is NOT able to delete the newly created repeat record even though the allowAdds=true.  This I'm quite happy about but wasn't expecting it.

Thanks again and I look forward to any further input / advice you might have.

Cheers, BKS

0 Kudos
abureaux
MVP Frequent Contributor

Sounds like you have a good solution there! If you have no more questions, don't forget to mark your response as the accepted solution so others can benefit.

"...IF the parent record has zero associated repeat recs, it automatically creates 2 repeat records the first time..."

Sounds like you need to beef up your calculate a little. On that note, two things:

  • the repeat_count column doesn't always like doing math. A simple solution is to put your calculate in to a calculate field, and then reference that calculate in the repeat_count column. This can help resolve lots of little unforeseen issues.
  • Building on what I have above, use an IF() statement in a separate calculate. Something like this should work:
    if(count(${test_rpt})=0,1,once(count(${test_rpt})+1))
    I had a similar issue with my second attempt and ended up with the blow, which is effectively the same thing:
    abureaux_0-1715782238110.png

     

"I'm hoping that there might be a way to use position(..) and/or index to have the survey open to the last (most recent) repeat record."

This is a common ask. Unfortunately, the answer is "cannot be done" (at least presently).

"...the user is NOT able to delete the newly created repeat record..."

This is expected behaviour. As soon as you use the repeat_count column, the option to add or delete records goes away.

0 Kudos
BKS
by
Frequent Contributor

Thanks again to you both @abureaux and @jcarlson .

I will try the remaining suggestion to avoid the 2 repeat recs being created if zero exist the first time and get back.  RE: other two points, thanks for the confirmation info.

Your help is most appreciated.

BKS

0 Kudos