How to prevent duplicate Drop-down field entries?

How can I prevent duplicate data on the Drop-down field?

Unfortunately, the Drop-down field does not support Prohibit duplicate values setting.

Screenshot of the App with the Drop-down field:

Screenshot of Drop-down field’s settings:

Hi @Jayron_Rosel,

Could you kindly elaborate on the reason why it has to be the dropdown field and what it is exactly that you are trying to do?

Hello Sean_Tcbn,

I’m creating driver’s scheduling app, so I put two drop down list for driver name and car name.
then I want to prohibit duplicate entry to avoid conflict scheduling on the availability of the driver and car.

Here is the screenshot:

The content of my app:

The content of my drown down settings:
Driver’s name:

Car:

I hope you can help me with my problem, thank you so much sir.

Hi @Jayron_Rosel,

Thanks for sharing that.

Based on your provided information, checking for duplicates before saving the records would be easier.

The following APIs are available in the “kintone” API.

In the event before saving the record create and record edit screens, if an error message is assigned to the event object’s error, and the event object is returned, an error message is displayed at the top of the screen, and the record cannot be saved.

Also, by specifying the values set in “Driver Name” and “Car Details” in the “GET” REST API query to retrieve records in bulk, you can check for other records that have the same set of values.

So, if the same combination of values is set, an error message is displayed, and the record cannot be saved, and if the same combination of values is not set, the record is saved as is.

I think that would be the closest to your desired process/outcome.

Could you check that and see if it’s helpful to you?

1 Like

Hello Sir @Sean_Tcbn ,

Would it be possible if you could post an example script I can use?

Thank you for your time

Hello @Jayron_Rosel

Here is the sample:

(function() {
  "use strict";

  const Drop_down = "Drop_down";
  
  kintone.events.on([ 'app.record.create.change.' + Drop_down, 'app.record.edit.change.' + Drop_down], function(event) {
    let record = event.record;
    let item_no = record[Drop_down].value;
    let query = Drop_down + ' in("' + item_no + '") limit 1';
    let body = {
      'app':kintone.app.getId(),
      'query':query
    };

    kintone.api(kintone.api.url('/k/v1/records.json', true), 'GET', body, function(resp) {
      let rec_counts = resp.records.length;
      let retStr = null;

      if(rec_counts > 0){
        retStr = "Duplicate selection exists";
      }
      else{
        retStr = null;
      }

      // Displays in the message
      let recobj = kintone.app.record.get();
      console.log(recobj);
      recobj.record[Drop_down].error = retStr;
      kintone.app.record.set(recobj);
      
    });
  });

})();

Thank you so much sir, it works.

But it counts all the record, what I need is duplication within the day

Thank you in advance sir.

Hello @Jayron_Rosel ,

We are more than happy to help debug or improve your existing code.
Feel free to post specific questions or problems you have encountered as you are building a Kintone customizations.

This forum is for engineers of all levels, to seek Kintone customization advice from other engineers.

For requests on custom JavaScript implementations, please seek advice through the Kintone Partners page.