Solved

From Repeating Section List Lookup

  • 20 January 2021
  • 5 replies
  • 198 views

Badge +2

Hi everyone, 

I have an question that is connected mainly with te Repeating Section part of the Nintex Form. To give you some background I'll describe shorty what is a purpose of that repeating section.

 

Background:

I'm creating a from where coordinator will be able to sing their employees into our transport routes. And as there are many of them and they are busy they don't want to fill same form multiple times for different routes - they rather want to do it once by adding new routs as new repeating section parts - I totally understand that.

 

ISSUE:

BUT - there are 2 issues connected with that which affected the duplication issue for creating by same coordinator two identical route orders.

 

  • 1st issue that I solve by checking in the form if on the list (where I'm spiting that repeating section data into individual records) already is same route created by the coordinator - that worked.
  • 2nd issue is the one I'm struggling right now - how to prevent the coordinator of choosing same route in the next repeating section part that he already put previously.

 

Example: Coordinator is choosing routes:

  1. AAAAA
  2. BBBBB
  3. CCCCC

and above is totally fine, but the below

  1. AAAAA
  2. BBBBB
  3. CCCCC
  4. BBBBB

, should not be allowed as he picked BBBBB twice, and the perfect solution will be that he cannot add another part of repeating section before he fixed that (but completely enough will be to stooped him from saving the form at the end of his filling the form.

I was trying some actions with strings length and contains function but that was not successful.

 

Do you guys have any idea how i can prevent for double choosing same position from lookup list in the parts of repeating section?

 

I'll be very grateful for any hints 🙂

 

icon

Best answer by MegaJerk 26 January 2021, 00:36

View original

5 replies

Userlevel 5
Badge +14

Can you provide details on what the type of Control it is that contains the Route Names, or is it all typed in by hand?

If it's a Choice Control, that would be easiest, but knowing just that little bit more information is useful to creating a solution.

Thank you 

Badge +2

Hi, thanks for replay.


The Route Name is taken from the List Lookup filed from the another list where all of the possible routes are listed.

Userlevel 5
Badge +14

Alright. So here is a very simple example form: 



 


I have a single Repeating Section, and inside of that is a Lookup Control named "routeLookup", and a label next to it. It should be noted that in this example my Lookup is pointed towards a test list of Fruits. Do not be alarmed!

I have two (2) Validation Rules running on the Route Lookup Control:




The Rule named "SelectionEmpty" is simple enough and is as follows:



(note: this rule is so small that I'm going to bother writing the code out by itself)


 


This will make sure that you cannot submit the form if you've added a row that doesn't have a Route selected. If you do not care if people do this, then you can simply ignore this rule.


 


The next rule is called Selection Exists: 



 


The Formula for this rule is as follows:


(function(rowIndex) {

var currentControl = NWF$("#" + rowIndex);
var currentValue = currentControl.val();
var currentFormControlID = currentControl.attr("formcontrolid");

var currentRow = currentControl.closest(".nf-repeater-row");
var siblingRows = currentRow.siblings(".nf-repeater-row:not" + "(.nf-repeater-row-hidden)");
var siblingValues = [];

siblingRows.each(function(index,siblingRow){
siblingRow = NWF$(siblingRow);
siblingValues.push(NWF.FormFiller.Functions.GetValue(currentFormControlID, siblingRow));
});

return siblingValues.indexOf(currentValue) > -1;

}(rowIndex))

(note: you should be able to copy/paste the above code into the formula window and that's it!)


 


What this does is a only a tiny bit complicated, but I'll work through it with you. 


Here is the same code with comments explaining what's happening:


/* This function is what's called an: Immediately Invoked Function Expression, or IIFE for short.
They helpful to use inside of things like Validation Rules, because it's one way for us
to use JavaScript to do a bunch of work right there in the Rule without adding code elsewhere
in our Form.

If you'd like to know more about the ins and outs of how the Rule System works, please see
my blog at:

https://community.nintex.com/t5/Community-Blogs/Breaking-The-Rules-A-Dive-Into-The-Nintex-Forms-Rule-System/ba-p/78874

For now, just understand that the 'rowIndex' argument is provided by the built in Nintex
Validation Rule wrapper that this function (IIFE) is executing inside of, and contains the
ID of the Control that the Rule is being ran on!
*/
(function(rowIndex) {

/* Using the rowIndex, we can get a reference to the Control that was changed */
var currentControl = NWF$("#" + rowIndex);

/* Now we need to get its value */
var currentValue = currentControl.val();

/* Let's also get the 'formcontrolid' attribute as it will come in handy later */
var currentFormControlID = currentControl.attr("formcontrolid");

/* Now we can find the Repeating Section Row that the control is inside of */
var currentRow = currentControl.closest(".nf-repeater-row");

/* Once we have that, we need to get the OTHER rows next to that -
Ignoring the hidden and invisible 'root' Row that all of the other Repeating Section
Rows are created from */

/* Side Note: notice how I have to split the text after the keyword "not" because
Nintex Form searches all of the user input JS for certain function names to replace
them with their own built in funcitons. Unfortunately it does this even when the text
in question is not an actual function. However, breaking the string up so that it doesn't
have the open parenthesis next to it, prevents the Form from replacing it with something incorrect */
var siblingRows = currentRow.siblings(".nf-repeater-row:not" + "(.nf-repeater-row-hidden)");

/* last but not least we need an empty array to hold all of the values that aren't the one
for the control this Rule is running on */
var siblingValues = [];

/* With our variables setup, we'll loop through each other Row
IF there are other rows to loop through! */
siblingRows.each(function(index,siblingRow){

/* Here we just make sure that the siblingRow argument is a jQuery object */
siblingRow = NWF$(siblingRow);

/* Then we PUSH the value of the Control in question, from that Sibling Row, into the
"siblingValues" array */
siblingValues.push(NWF.FormFiller.Functions.GetValue(currentFormControlID, siblingRow));
});

/* Once we are done we need to check and see if the currentValue is found inside of the
siblingValues array. To do this we use the built in "indexOf()" function which will return
a value ABOVE -1 if our currentValue is found inside of siblingValues.

Because of this we can use it as the return value by checking if its value is greater than -1.

This will return true (INVALID) if the value IS found, and false (VALID) if it isn't */
return siblingValues.indexOf(currentValue) > -1;

}(rowIndex))

 


The results should be straight forward enough. 


 


Trying to Submit the Form with an empty Route will result in an error: 



 


Likewise trying to submit the form with a duplicate Route Value will result in an error also



 


I hope that this helps to solve your problem. 


 

Badge +2

Hi,


Thank you very much for your help - that works perfectly as I wanted 🙂


 


Have a nice day and once again - thank you! 

Userlevel 5
Badge +14

That's very good to hear! good luck!

Reply