Constraint Based on Value in Another Field from a Previous Repeat

709
5
02-02-2022 02:11 PM
JohnRagosta
New Contributor II

I am trying to add a constraint to a field based on the value from another field from a previous repeat.  I have more or less figured this out using the position(..) function coupled with the indexed-repeat() function.  The problem is that it doesn't work for the first record (where previous value = null), unless I ask the user to enter a 0 for the first record.  But ultimately I don't want that field to be changed intentionally in the case of the first record or unintentionally for subsequent records (I'll eventually figure out how to have that value displayed but not alterable, which is another issue altogether).    

I tried to create a component of the constraint using ISNULL (e.g. ${start_gap}<=9980 and (${start_gap}> ${prev_end_gap} or ISNULL(${prev_end_gap}))).  But that did not solve the problem. 

Help with this is much appreciated.

John Ragosta

Tags (1)
0 Kudos
5 Replies
DougBrowning
MVP Esteemed Contributor

For my gap if you are going down the line I just check max().  No need to go to the last repeat since the max is always in order.

I have a full Gap form that we use at the BLM.  I cannot post it but if you are in a related industry contact me and I can give you a copy.

Hope that helps

0 Kudos
JohnRagosta
New Contributor II

Thanks, Doug.  I reached out to you bc I am in a related industry and would love a copy of that form.  I tried the max() function, but I still had an issue with the first record, for which the "prev_end" was still null.  But thinking about it more, I'm considering eliminating the repeat and just having all of the start and ends on the same form.  

 

0 Kudos
DougBrowning
MVP Esteemed Contributor

Well we show them the last gap since it is not automatic that the end will be the new start.  We check against the last to make sure the new start is more than 2 cm past the last one.

DougBrowning_0-1644264700910.png

 

In your case for the first one a if should do it.  if(position(..) = 1, 0, max(gapend))

If you dont use a repeat then how can you vary how many gaps there might be?  Maybe you do it different but ours can vary from no gaps to a whole bunch.

I sent your info along and you should get the forms soon.  thanks

0 Kudos
JohnRagosta
New Contributor II

great question.  For now (or at least until I can code a better solution), I am just adding start_gap2, start_gap3, until I've reached a number beyond what we might expect (10 gaps along a 1,000 cm line?). 

That said, I can vary the number of gaps that show on the tool by putting some constraints and relevants to reveal the next entry field (or not). The end_gap of the previous record must be smaller than the next start_gap. After entering an end_gap, a new start_gap (start_gapn) will appear unless the "relevant" condition for start_gapn is ${end_gap} <= 9980 is not met.  (The 9980 represents 20 cm prior to the end of the line; 20 cm being the minimum gap size.)  But the last gap may come well before that in which case the user will leave start_gapn blank.  Usign the repeats, I was able to get the Previous End Gap to display, but (back to the original problem) the first value was Null and that was violating my constraint on the start_gap: ${start_gap}<=9980 and (${start_gap}> ${prev_end_gap} or ISNULL(${prev_end_gap}).  The ISNULL didn't work.  

I see your additional suggestion.  I'll give that a try. 

0 Kudos
DougBrowning
MVP Esteemed Contributor

Well at this point now that I know we use the same method I will just give you all the forms.  We have all 9 from the protocol.  Sent you a pm.  thanks

0 Kudos