Ways to prevent Duplicates during data entry ?

I have a modal dialog for adding a widget.
If I have a field like SSN (Social Security Number) that must be unique, should I:

  1. Check at the time the field is entered ?
    I’ve noticed if I use an “on-change…” then the function gets called on each digit entered.
    Thats going to throw false hits because I only want to check when I leave the field.
    But I don’t see an option for that.

  2. Check at the time the record is saved ?
    I don’t feel this is the best, as the user should be alerted at the time of the error when leaving the field, but if I do this, what do I do to cancel the SAVE action and stay on the modal dialog?
    I’d like to display some kind of alert, and then just pretend the SAVE button wasn’t pressed.
    Is there some ‘break’ function that will stop the SAVE, or do I need to have all my existing SAVE code in an ELSE block so it only happens when a DUP was not found ?

function check_ssn {
IF $search_for_dup()
THEN Alert “duplicate SSN - cannot continue”
ELSE {
db.save etc etc
}
}

BUMP

  1. Surprised that no one seems to have ever run across this
  2. Surprised there’s so little activity on the board that it has only 5 views

After an initial 2000-unit Inventory Job, I am cleaning up data from duplicate entries.
Kinda a pain.

I did add my 2nd option - and it works fine - except it doesn’t alert until the user SAVEs his overall work. So he’s taken time to enter in a serial # and other fields, PLUS taken several pics, only to be told when he SAVEs that it was a waste of time.

Is there no way to indicate “unique” / “duplicates not allowed” in the Data Model ?

1 Like

@jaymer You cannot force uniqueness on the DB level as the DB are all distributed, so there is no way for one device to know if another device has already created that unique entry.

The only way to ensure uniqueness is on the server, either via CloudCode or via an OnlineDB call.

Reading between the lines of your first post, it sounds like you may want to look into the auto-hide attribute of the XML dialog. When that is set to false, you can run the necessary validations in JS|TS and simply return and not hide the dialog which would allow the user to correct their entry.

As for validating at time of entry, that works for simple validations, like “does the entered value have enough characters” or “is the date my birthday” (it’s February 3rd, just fyi), but for something where you need to query the DB to validate, you will have a better time doing it once the user presses a button, or something like that.

OK, I buy this ‘in general’, but what if today only 1 operator was on-site validating assets. There is no other device, so searching for the DB.AssetTag would be valid. And if no one is offline, they in some short time they will all have the same DB.
IF YOU ABSOLUTELY POSITIVELY have to have 100% NO DUPS, then I see your point.
In my case, AssetTag cannot have dups in MSSQL (via Constraint), so my SP fails when trying to Add, which leaves the item un-uploaded to SQL in my App. Then it has to be researched later to see why it was a Dup and AssetTag changed before it can go to SQL.

So if I can eliminate 70, 80, 90% of Dups because I’m alerting the user while he is at the item, then thats better that cleaning up 100% later.

If I ran a CC task, couldn’t that take UP TO 5-10 seconds to return?

I believe I can determine if I’m online or not, correct?
If so, I could check OnlineDB.
Right now I’m doing this in my SaveAsset() function:
let existing_asset = await DB.asset.first("asset_tag = ?", view.asset.asset_tag);

So while not 100% foolproof, if I’m offline, then check my own copy of the DB. If online, then hit the OnlineDB to be sure another user hasn’t added the same asset.
In our first project, it was the same user making errors by not properly marking items he already inventoried. And then doing it again 15 minutes later. :roll_eyes:

Well, exactly what operation does this “at time of [field] entry”?
Because “on-change” isn’t the way, since it fires (for me) after each character. (as written in the OP)
So forget Duplicate DBs entries for a sec, how would I fire a function when I LEAVE a field? I must have missed something in the docs.
Even your example here validates after a SAVE is pressed.
For reasons in my above posts I’ve claimed that having a user enter a lot of data, and take pics, only to get a warning at SAVE time is poor UI. And that happened several times during our project.

It would be a nice improvement, if for a TEXT field (at least), we could indicate additional Validation like shown here:

What if there was a way to do this:
text:validate(check_length) where “check_length” was a user function.
tech:validate(check_dup)
or even
text:email:validate(check_domain)
I mean, you’re already running some hardcoded function to provide the Additional Validation for some subtypes like email, phone-number, etc. This would still validate the EMAIL, and then run the custom function if EMAIl validation passed.

this has got to be a ton better than doing some validations at SAVE time.

Either that or a new modifier like “on-exit”, “on-leave”, etc. , that runs when you tab out of a field.

Well, this was simple “return;” statement needed in the JS.
If the Save was valid (no dup found), then it proceeds, but if not I throw an alert and “return;” and the dialog stays active.

1 Like

Agreed. Currently we don’t have any “hooks” for things like on-focus or on-leave, so you’ll have to make due with running the validations on save, unless you are just doing calculations in which case putting a warning inside something like a modifier-text field which re-evaluates on every key stroke (either with on-change or just having the content of the modifier-text attribute be bound to the output of a function) could provide the type of validation UI you are looking for