Skip to main content
Nintex Community Menu Bar

Scenario: We have two lookup column . Column A contains Country and Column B contains Sites.

Based on country selection sites will get filter out .

Issue: Since Sites contains duplicates value , in drop-down also it get visible.

Solution: 1. In nintex form , save client id for the column B dropdown in nintex form. In below code client id is "txtsite".

Then using $("select[id="+txtsite+"]>option") we get all list of values in dropdown .

On "Mousedown" event , create array and check each value of dropdown , if value is already in array remove value otherwise add value to array. Once all check has been done, assign back the array to control value.

 

<script type="text/javascript">

//<!!CDATAA

 

NWF$(document).ready(function(){

    NWF$("#"+txtsite).on('mousedown',function(){

var usednames={};

$("selectsid="+txtsite+"]>option").each(function(){

if(usednamesdthis.text]){

                $(this).remove();

            }

            else{

                usednames this.text]=this.value;

            }

 

 });

 

 });

});//]]>

</script>

<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>

OK, 2 of the items were my fault - some days I'm a "genius."  The control was working as planned and filtering them out because I'd changed a setting while testing another workflow.  

But the last item is one I manually added to the list. It shows up in the Active Projects view on the list (which the control is being filtered by), but not as an option in the form.

Active View (that the Resource control is filtered through):

For good measure, sample project details.  All required items are filled out.
I

I wouldn't ordinarily worry about it, but once these items go live, I will still need to test things from time in case something breaks, and I will need to enter "dummy" data to do that so I don't affect live projects or the processes related to them.


Unfortunately, I cannot think of any reason a value would be appearing in the view on the list, but not coming through in the List Lookup using that view. Perhaps you can try removing the view filter in the List Control, removing or commenting out the JavaScript, and simply have the List Lookup return absolutely everything just to see if it comes through without any filters anywhere. If it still doesn't come through, I'm really not sure what to tell you. However, if it does, then you know it's somehow being caught by a filter somewhere.


Thanks Chad.

I will try that and a few other things. Made no sense to me either. But at least the other part was a user error and not an actual problem.

Thanks again. The java script will help with this solution tremendously.


Solved the problem. To see all possible values in that field, I had to leave the Source View blank and have Filter set to Display all items.  Then, in the connected Project ID control, I can apply the Source view (to only show Active Projects) and have it filter based on the Resource control.

I'm guessing, I can either filter that control using java to remove the duplicates or via Source view.  But it doesn't like the combination, which is fine since the Source view can be applied to the Project ID control to produce the same effect:  Showing only Active project IDs for a specific person.

Thanks so much for all your help.


I'm glad you solved the problem!


I'm guessing I missed a step in your solution (I switched to classic from responsive!). 

I added the script to the form settings:

Then I updated the control css class on the drop down(s):

Any idea what I am doing wrong? Duplicates continue to show up. 


You'll want to put it in the Custom JavaScript section, not in the Advanced -> Custom JavaScript Includes section:

However, yours looks like it jumps from Advanced to Print to PDF. Do you have these other sections?


Ahh okay. Yes I put it in the correct place. But now it won't show anything. When I select Product, the other drop downs don't update. 


I'd need a lot more information about how your form is setup. I don't know how your filters are setup, or how your drop downs are populated.


Great post..Chad Davis

I need a small help.

 

In my ListA, I have 3 lookup Columns coming from the same list.

Parent List Name: Location Details

Columns: Region, Country and City

 

I need a cascaded dropdown with these 3 fields on ListA.

Doesnt want to create multiple list to achieve it,

So I have applied filter on Country Dropdown to filter it by Region control and in the same way applied filter on City Dropdown to filter it by Country control.

 

Your code works perfect initially to remove duplicates on all these 3 dropdowns, but on change of Region, its filtering the values in Country and pulls all duplicate values again.

Could you please suggest a best way to filter it and remove the duplicates appropriately .


Hello Davis 

Thank you for this nice snippet.

 

For me, it works only in the Form-Preview, when I save and publish the Form and create an New Item, the duplicate Entries are no removing.

 

Its very interesting that the Code snippet only worked in the Form-Preview Mode, do you have any idea what could be the issue?


I apologize for not getting back to you sooner. I don't remember receiving a notification for your question.

To answer your question, since the lookup fields are being repopulated from each other, the code isn't being rerun each time. The code currently only runs on page load. If you'd like to have it run every time, you'll have to add in another type of listener.

I would suggest an on click or on change listener of some sort. I don't have time to create an example for you right now, but I will post one so it can help others too.

One really nice feature of the code is that it's in a function so, you can call it as many times and from as many different areas of your code as you need.


I'll be honest, I'm stumped by this one. If it works in preview, it should work in the published form as well.

One suggestion you might try:

For some reason, I have had a couple situations where I had to replace each $ with NWF$ in the code. I have no idea if this is what's happening for you too, since in my situations it didn't work in the preview or publish. However, it's worth a try.

Aside from that, I would suggest posting your code and giving screenshots of your form, its controls, and maybe even the list to help troubleshoot.

Another suggestion would be to add the console.log code I suggested above. You could even tweak it to show additional information as the form loads. I find the console in Chrome to be a huge help in discovering why code isn't working as it should.


Love it!! but sadly it does not work on Filtered lookup fields... 


Hello Davis

Thanks for the Feedback, I found the solution.

To put NWF before the $ was one thing, but in my case I had a .js File linked with the Form. 

After I putted your code in the js File and corrected the $, the duplicates were gone .

Thank You!!


I'm very glad to hear you were able to get it to work. 
In the past, I was able to use the $ by itself, but now it seems NWF$ has to replace it whether you use a Nintex JavaScript variable or not. I'm not sure if that has changed in a recent update.


I'm surprised to hear it isn't working on filtered lookup fields. The code shouldn't care how the data gets populated to the control. It simply loops through whatever options it has, confirms each option doesn't already exist, and removes it if it does.

Can you add the console.log lines to the code that I suggested above? This should help you in debugging the issue.


I can't get rid of the duplicates in a lookup dropdown field. Any help would be appreciated. I've added "duplicates" to control CSS class and the code into Custom Javascript in Settings.

 


Has anybody been able to solve this?  I tried the javascripts and made sure the Client ID JavaScript variable name  is correct, but it won't remove the duplicates.  I'd rather not have to make 3 lists to do a cascading drop down since I already have a ton of data in one list. 


I am having the same issue as a few others where the javascript will not work as soon as I apply filters on the lookup. Has anyone found a solution for this? I am not great at javascript, so if someone could provide an example, that would be great.



 



I have tried this two ways:



NWF.FormFiller.Events.RegisterAfterReady(function(){
     $('.duplicates').each(function(){Update(this.id);});
});
function Update(control){
     var usednames={};
     $("select[id="+control+"]>option").each(function(){
          if(usednames[this.text]){$(this).remove();}           
          else{usednames[this.text]=this.value;}  
     });
}



 



with filter of





I have also tried the following with same filter as above:



NWF.FormFiller.Events.RegisterAfterReady(function(){



 NWF$(document).ready(function(){   



 });   var txtsite_var =
txtsite.replace("_hid", "");



 NWF$("#"+txtsite_var).on('mousedown', function(){



 var usednames={};



 NWF$("select[id="+txtsite_var+"]>option").each(function(){



 if(usednames[this.text]){                



 NWF$(this).remove();           




 }           



 else{               




 usednames[this.text]=this.value;           




 }   });



 });



});



 



As soon as I remove the lookup filter, it works great to remove the duplicates.


Chad Davis' solution (posted on 4/23/2018 10:12 AM) worked perfectly for me.  In the Custom Javascript I had to change $ to NWF$ otherwise I'd get error messages in the console that it couldn't find the object I was referencing, but otherwise it worked as advertised and was pretty fast too on a long list with many duplicates.   Thanks, Chad!


Reply